JezK
Edit File: settings.php
<?php include("header.php"); ?> <style> div.dataTables_wrapper div.dataTables_filter { position: absolute; top: 154px; } .page { height: 100% !important; } </style> <section class="section-padding px-4 "> <div class="container bg-white "> <div class="row"> <div class="col-12 col-sm-6 col-lg-5 my-3" style="padding-bottom:118px;"> <h6 class="mb-4">CHANGE PASSWORD</h6> <div class="form-group"> <div class="d-flex align-items-center justify-content-between"> <label for="oldpassword" class="fieldName">Current Password</label> <button type="button" onclick="showPassword(1)" class="btn bg-transparent shadow-none text-custom-primary p-0" id="currentpassword">Show</button> </div> <input type="password" class="form-control formField-control" name="oldpassword" id="oldpassword" onkeypress="return checkSpace(event)" onpaste="return false"> </div> <div class="form-group"> <div class="d-flex align-items-center justify-content-between"> <label for="password" class="fieldName">New Password</label> <button type="button" onclick="showPassword(2)" class="btn bg-transparent shadow-none text-custom-primary p-0" id="newpassword">Show</button> </div> <input type="password" class="form-control formField-control" name="password" id="password" onkeypress="return checkSpace(event)" onpaste="return false"> </div> <div class="form-group"> <div class="d-flex align-items-center justify-content-between"> <label for="confirmPassword" class="fieldName">Confirm Password</label> <button type="button" onclick="showPassword(3)" class="btn bg-transparent shadow-none text-custom-primary p-0" id="cpassword">Show</button> </div> <input type="password" class="form-control formField-control" name="confirmPassword" id="confirmPassword" onkeypress="return checkSpace(event)" onpaste="return false"> </div> <div class="form-group mt-4 mb-2"> <button type="submit" class="btn basic-btn-color w-100" onclick="return changepassword();">Confirm</button> </div> </div> </div> </div> </section> <?php include("footer.php"); ?> <script type="text/javascript"> function checkSpace(e) { var key = e.keyCode if(key == 32) { alert("Space is not allowed in the password"); return false; } return true; } function showPassword(inputValue) { if (inputValue === 1) { var currentPasswordType = document.getElementById('oldpassword'); if (currentPasswordType.type === 'password') { currentPasswordType.type = 'text'; $('#currentpassword').html('Hide'); } else { currentPasswordType.type = 'password'; $('#currentpassword').html('Show'); } } if (inputValue === 2) { var currentPasswordType = document.getElementById('password'); if (currentPasswordType.type === 'password') { currentPasswordType.type = 'text'; $('#newpassword').html('Hide'); } else { currentPasswordType.type = 'password'; $('#newpassword').html('Show'); } } if (inputValue === 3) { var currentPasswordType = document.getElementById('confirmPassword'); if (currentPasswordType.type === 'password') { currentPasswordType.type = 'text'; $('#cpassword').html('Hide'); } else { currentPasswordType.type = 'password'; $('#cpassword').html('Show'); } } } function changepassword() { if($('#oldpassword').val()=='') { alert('Please enter current password');return false; } else if($('#password').val()=='') { alert('Please enter new password');return false; } else if($('#confirmPassword').val()=='') { alert('Please enter confirm password');return false; } else if(($('#password').val()).length<=5) { alert('New password must be more than 5 characters');return false; } else if($('#password').val()!=$('#confirmPassword').val()) { alert('New Password and Confirm Password should be same');return false; } else if($('#password').val()==$('#oldpassword').val()) { alert('Current Password and New Password should not be same');return false; } else{ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if(this.responseText == 1){ alert("Your password is successfully updated"); window.location="dashboard.php"; }else if(this.responseText==0){ alert("Password updation was failed"); return false; } else if(this.responseText==-1){ alert("Current Password is not matched"); return false; } } }; xmlhttp.open("POST", "ajax.php?oldpwd=" + $('#oldpassword').val() +"&newpwd="+$('#password').val()+"&action=checkcurrentpassword", true); xmlhttp.send(); } } </script>