Add password error check
This commit is contained in:
parent
13a2d72bad
commit
34426bebfd
|
@ -45,20 +45,26 @@ public class ResetPasswordServlet extends HttpServlet {
|
|||
String password = request.getParameter("password");
|
||||
String confirmPassword = request.getParameter("password_conf");
|
||||
|
||||
// if (username != null) {
|
||||
|
||||
if (password.equals(confirmPassword) && username != null) {
|
||||
try {
|
||||
ldapActions.resetPassword(username, password);
|
||||
logger.info("password resetted");
|
||||
if (password.equals(confirmPassword) && username != null) {
|
||||
try {
|
||||
ldapActions.resetPassword(username, password);
|
||||
logger.info("password resetted");
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("LDAP error in resetting password", e);
|
||||
response.sendRedirect("./error.jsp");
|
||||
} catch (Exception e) {
|
||||
logger.error("LDAP error in resetting password", e);
|
||||
response.sendRedirect("./error.jsp");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
session.removeAttribute("username");
|
||||
response.sendRedirect("./success.jsp");
|
||||
printWriter.close();
|
||||
session.removeAttribute("username");
|
||||
response.sendRedirect("./success.jsp");
|
||||
printWriter.close();
|
||||
|
||||
// } else {
|
||||
// response.sendRedirect("./forgotPassword.jsp");
|
||||
// printWriter.close();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ function validateForm() {
|
|||
var password_conf = $("#password_conf").val();
|
||||
|
||||
var isValidEmail = validateEmail(email);
|
||||
var isValidPassword = validatePassword(password);
|
||||
var hasError = false;
|
||||
var isEmailFilled = false;
|
||||
var isPasswordFilled = false;
|
||||
|
@ -121,16 +122,33 @@ function validateForm() {
|
|||
}
|
||||
|
||||
if(isPasswordFilled) {
|
||||
// Check if passwords match
|
||||
if (!confirm(password, password_conf)) {
|
||||
$("#password").addClass('uk-input aai-form-danger');
|
||||
$("#password_conf").addClass('uk-input aai-form-danger');
|
||||
$(".msg_pass_conf_error").show();
|
||||
hasError = true;
|
||||
} else {
|
||||
$(".msg_pass_conf_error").hide();
|
||||
}
|
||||
// Check if passwords match
|
||||
if (!confirm(password, password_conf)) {
|
||||
$("#password").addClass('uk-input aai-form-danger');
|
||||
$("#password_conf").addClass('uk-input aai-form-danger');
|
||||
$(".msg_pass_conf_error").show();
|
||||
hasError = true;
|
||||
} else {
|
||||
$(".msg_pass_conf_error").hide();
|
||||
}
|
||||
}
|
||||
|
||||
if(!isValidPassword) {
|
||||
$("#password").addClass('uk-input aai-form-danger');
|
||||
$(".msg_please_add").show();
|
||||
$(".msg_lowercase_letter").show();
|
||||
$(".msg_capital_letter").show();
|
||||
$(".msg_number").show();
|
||||
$(".msg_lenght").show();
|
||||
hasError = true;
|
||||
} else {
|
||||
$("#password").removeClass('aai-form-danger');
|
||||
$(".msg_please_add").hide();
|
||||
$(".msg_lowercase_letter").hide();
|
||||
$(".msg_capital_letter").hide();
|
||||
$(".msg_number").hide();
|
||||
$(".msg_lenght").hide();
|
||||
}
|
||||
}
|
||||
|
||||
return !hasError;
|
||||
|
@ -141,6 +159,11 @@ function validateEmail(email) {
|
|||
return re.test(email);
|
||||
}
|
||||
|
||||
function validatePassword(password) {
|
||||
var pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}$/;
|
||||
return pattern.test(password);
|
||||
}
|
||||
|
||||
function confirm(first, second) {
|
||||
if (first == second)
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%--<% if (session.getAttribute("username") == null) {--%>
|
||||
<%--String redirectURL = "/dnet-openaire-users-1.0.0-SNAPSHOT/forgotPassword.jsp";--%>
|
||||
<%--response.sendRedirect(redirectURL);--%>
|
||||
<%--}--%>
|
||||
<%--%>--%>
|
||||
<%--<%String name=(String)request.getAttribute("name");--%>
|
||||
<%--out.print("your name"+name);%>--%>
|
||||
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
|
||||
|
@ -45,7 +50,7 @@
|
|||
<!-- CENTER SIDE -->
|
||||
<div class="uk-width-1-1@m uk-width-1-1@s uk-text-center">
|
||||
<div class="middle-box text-center loginscreen animated fadeInDown ">
|
||||
<p>To complete the password reset process, please enter a new password.</p>
|
||||
<p>To complete the password reset process, please enter a new password. <b>Must contain at least one number and one uppercase and lowercase letter, and at least 6 or more characters.</b></p>
|
||||
<div class="uk-width-1-3@m uk-align-center">
|
||||
<!-- REGISTER FORM -->
|
||||
<div id="registerForm">
|
||||
|
@ -56,7 +61,14 @@
|
|||
<div class="form-group">
|
||||
<span class="msg_password_error uk-text-danger uk-text-small uk-float-left" style="display:none">Please enter your password.</span>
|
||||
<span class="msg_pass_conf_error uk-text-danger uk-text-small uk-float-left" style="display:none">These passwords don't match.</span>
|
||||
<input id="password" name="password" type="password" placeholder="Password" class="form-control"></div>
|
||||
<p><span class="msg_please_add uk-text-danger uk-text-small uk-float-left" style="display:none">Please add:  </span></p>
|
||||
<li><span class="msg_lowercase_letter uk-text-danger uk-text-small uk-float-left" style="display:none">A lowercase letter.  </span></li>
|
||||
<li><span class="msg_capital_letter uk-text-danger uk-text-small uk-float-left" style="display:none">A capital (uppercase) letter.   </span></li>
|
||||
<li><span class="msg_number uk-text-danger uk-text-small uk-float-left" style="display:none">A number.  </span></li>
|
||||
<li><span class="msg_lenght uk-text-danger uk-text-small uk-float-left" style="display:none">Minimum 6 characters.  </span></li>
|
||||
<div id="message">
|
||||
</div>
|
||||
<input id="password" name="password" type="password" placeholder="Password" class="form-control"></div>
|
||||
<div class="form-group">
|
||||
<input id="password_conf" name="password_conf" type="password" placeholder="Confirm password" class="form-control"></div>
|
||||
<div class="uk-margin uk-grid-small uk-child-width-auto uk-grid uk-text-left uk-grid-stack" uk-grid="">
|
||||
|
@ -68,16 +80,76 @@
|
|||
</div>
|
||||
<!-- END OF REGISTER FORM -->
|
||||
<script>
|
||||
$("#password").focusin(function() {
|
||||
$(this).removeClass('aai-form-danger');
|
||||
$(".msg_password_error").fadeOut();
|
||||
$(".msg_pass_conf_error").fadeOut();
|
||||
});
|
||||
|
||||
$("#password_conf").focusin(function() {
|
||||
var myInput = document.getElementById("password");
|
||||
|
||||
// When the user starts to type something inside the password field
|
||||
myInput.onkeyup = function() {
|
||||
|
||||
// Validate lowercase letters
|
||||
var lowerCaseLetters = /[a-z]/g;
|
||||
if (myInput.value.match(lowerCaseLetters)) {
|
||||
$(".msg_lowercase_letter").fadeOut();
|
||||
} else {
|
||||
//$(".msg_please_add").fadeIn();
|
||||
$(".msg_lowercase_letter").fadeIn();
|
||||
}
|
||||
|
||||
// Validate capital letters
|
||||
var upperCaseLetters = /[A-Z]/g;
|
||||
if (myInput.value.match(upperCaseLetters)) {
|
||||
$(".msg_capital_letter").fadeOut();
|
||||
} else {
|
||||
//$(".msg_please_add").fadeIn();
|
||||
$(".msg_capital_letter").fadeIn();
|
||||
}
|
||||
|
||||
// Validate numbers
|
||||
var numbers = /[0-9]/g;
|
||||
if (myInput.value.match(numbers)) {
|
||||
$(".msg_number").fadeOut();
|
||||
} else {
|
||||
//$(".msg_please_add").fadeIn();
|
||||
$(".msg_number").fadeIn();
|
||||
}
|
||||
|
||||
// Validate length
|
||||
if (myInput.value.length >= 6) {
|
||||
$(".msg_lenght").fadeOut();
|
||||
} else {
|
||||
//$(".msg_please_add").fadeIn();
|
||||
$(".msg_lenght").fadeIn();
|
||||
}
|
||||
|
||||
if(myInput.value.match(lowerCaseLetters) && myInput.value.match(upperCaseLetters)
|
||||
&& myInput.value.match(numbers) && (myInput.value.length >= 6)){
|
||||
if($(".msg_please_add").css('display')!='none'){
|
||||
$(".msg_please_add").fadeOut();
|
||||
}
|
||||
} else {
|
||||
if($(".msg_please_add").css('display')=='none') {
|
||||
$(".msg_please_add").fadeIn();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$("#password").focusin(function () {
|
||||
$(this).removeClass('aai-form-danger');
|
||||
$(".msg_please_add").fadeOut();
|
||||
$(".msg_password_error").fadeOut();
|
||||
$(".msg_pass_conf_error").fadeOut();
|
||||
$(".msg_lowercase_letter").fadeOut();
|
||||
$(".msg_capital_letter").fadeOut();
|
||||
$(".msg_number").fadeOut();
|
||||
$(".msg_lenght").fadeOut();
|
||||
});
|
||||
|
||||
$("#password_conf").focusin(function () {
|
||||
$(this).removeClass('aai-form-danger');
|
||||
$(".msg_pass_conf_error").fadeOut();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</div>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue