Project

General

Profile

« Previous | Next » 

Revision 49551

Added by Sofia Baltzi over 5 years ago

Add password error check

View differences:

modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ResetPasswordServlet.java
45 45
        String password = request.getParameter("password");
46 46
        String confirmPassword = request.getParameter("password_conf");
47 47

  
48
//        if (username != null) {
48 49

  
49
        if (password.equals(confirmPassword) && username != null) {
50
            try {
51
                ldapActions.resetPassword(username, password);
52
                logger.info("password resetted");
50
            if (password.equals(confirmPassword) && username != null) {
51
                try {
52
                    ldapActions.resetPassword(username, password);
53
                    logger.info("password resetted");
53 54

  
54
            } catch (Exception e) {
55
                logger.error("LDAP error in resetting password", e);
56
                response.sendRedirect("./error.jsp");
55
                } catch (Exception e) {
56
                    logger.error("LDAP error in resetting password", e);
57
                    response.sendRedirect("./error.jsp");
58
                }
57 59
            }
58
        }
59 60

  
60
        session.removeAttribute("username");
61
        response.sendRedirect("./success.jsp");
62
        printWriter.close();
61
            session.removeAttribute("username");
62
            response.sendRedirect("./success.jsp");
63
            printWriter.close();
64

  
65
//        } else {
66
//            response.sendRedirect("./forgotPassword.jsp");
67
//            printWriter.close();
68
//        }
63 69
    }
64 70
}
modules/dnet-openaire-users/trunk/src/main/webapp/resetPassword.jsp
1 1
<!DOCTYPE html>
2 2
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
3
<%--<% if (session.getAttribute("username") == null) {--%>
4
  <%--String redirectURL = "/dnet-openaire-users-1.0.0-SNAPSHOT/forgotPassword.jsp";--%>
5
  <%--response.sendRedirect(redirectURL);--%>
6
  <%--}--%>
7
<%--%>--%>
3 8
<%--<%String name=(String)request.getAttribute("name");--%>
4 9
  <%--out.print("your name"+name);%>--%>
5 10
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
......
45 50
              <!-- CENTER SIDE -->
46 51
              <div class="uk-width-1-1@m uk-width-1-1@s uk-text-center">
47 52
                <div class="middle-box text-center loginscreen animated fadeInDown ">
48
                  <p>To complete the password reset process, please enter a new password.</p>
53
                  <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>
49 54
                  <div class="uk-width-1-3@m uk-align-center">
50 55
                      <!-- REGISTER FORM -->
51 56
                      <div id="registerForm">
......
56 61
                            <div class="form-group">
57 62
                              <span class="msg_password_error uk-text-danger uk-text-small uk-float-left" style="display:none">Please enter your password.</span>
58 63
                              <span class="msg_pass_conf_error uk-text-danger uk-text-small uk-float-left" style="display:none">These passwords don't match.</span>
59
                              <input id="password" name="password" type="password" placeholder="Password" class="form-control"></div>
64
                              <p><span class="msg_please_add uk-text-danger uk-text-small uk-float-left" style="display:none">Please add: &nbsp</span></p>
65
                              <li><span class="msg_lowercase_letter uk-text-danger uk-text-small uk-float-left" style="display:none">A lowercase letter. &nbsp</span></li>
66
                              <li><span class="msg_capital_letter uk-text-danger uk-text-small uk-float-left" style="display:none">A capital (uppercase) letter. &nbsp </span></li>
67
                              <li><span class="msg_number uk-text-danger uk-text-small uk-float-left" style="display:none">A number. &nbsp</span></li>
68
                              <li><span class="msg_lenght uk-text-danger uk-text-small uk-float-left" style="display:none">Minimum 6 characters. &nbsp</span></li>
69
                              <div id="message">
70
                              </div>
71
                                <input id="password" name="password" type="password" placeholder="Password" class="form-control"></div>
60 72
                              <div class="form-group">
61 73
                                <input id="password_conf" name="password_conf" type="password" placeholder="Confirm password" class="form-control"></div>
62 74
                              <div class="uk-margin uk-grid-small uk-child-width-auto uk-grid uk-text-left uk-grid-stack" uk-grid="">
......
68 80
                      </div>
69 81
                      <!-- END OF REGISTER FORM -->
70 82
                      <script>
71
                          $("#password").focusin(function() {
72
                            $(this).removeClass('aai-form-danger');
73
                            $(".msg_password_error").fadeOut();
74
                            $(".msg_pass_conf_error").fadeOut();
75
                          });
76 83

  
77
                          $("#password_conf").focusin(function() {
84
                        var myInput = document.getElementById("password");
85

  
86
                          // When the user starts to type something inside the password field
87
                          myInput.onkeyup = function() {
88
                            
89
                            // Validate lowercase letters
90
                            var lowerCaseLetters = /[a-z]/g;
91
                            if (myInput.value.match(lowerCaseLetters)) {
92
                              $(".msg_lowercase_letter").fadeOut();
93
                            } else {
94
                              //$(".msg_please_add").fadeIn();
95
                              $(".msg_lowercase_letter").fadeIn();
96
                            }
97

  
98
                            // Validate capital letters
99
                            var upperCaseLetters = /[A-Z]/g;
100
                            if (myInput.value.match(upperCaseLetters)) {
101
                              $(".msg_capital_letter").fadeOut();
102
                            } else {
103
                              //$(".msg_please_add").fadeIn();
104
                              $(".msg_capital_letter").fadeIn();
105
                            }
106

  
107
                            // Validate numbers
108
                            var numbers = /[0-9]/g;
109
                            if (myInput.value.match(numbers)) {
110
                              $(".msg_number").fadeOut();
111
                            } else {
112
                              //$(".msg_please_add").fadeIn();
113
                              $(".msg_number").fadeIn();
114
                            }
115

  
116
                            // Validate length
117
                            if (myInput.value.length >= 6) {
118
                              $(".msg_lenght").fadeOut();
119
                            } else {
120
                              //$(".msg_please_add").fadeIn();
121
                              $(".msg_lenght").fadeIn();
122
                            }
123

  
124
                            if(myInput.value.match(lowerCaseLetters) && myInput.value.match(upperCaseLetters)
125
                                && myInput.value.match(numbers) && (myInput.value.length >= 6)){
126
                              if($(".msg_please_add").css('display')!='none'){
127
                                $(".msg_please_add").fadeOut();
128
                              }
129
                            } else {
130
                              if($(".msg_please_add").css('display')=='none') {
131
                                $(".msg_please_add").fadeIn();
132
                              }
133
                            }
134

  
135

  
136
                            $("#password").focusin(function () {
78 137
                              $(this).removeClass('aai-form-danger');
138
                              $(".msg_please_add").fadeOut();
139
                              $(".msg_password_error").fadeOut();
79 140
                              $(".msg_pass_conf_error").fadeOut();
80
                          });
141
                              $(".msg_lowercase_letter").fadeOut();
142
                              $(".msg_capital_letter").fadeOut();
143
                              $(".msg_number").fadeOut();
144
                              $(".msg_lenght").fadeOut();
145
                            });
146

  
147
                            $("#password_conf").focusin(function () {
148
                              $(this).removeClass('aai-form-danger');
149
                              $(".msg_pass_conf_error").fadeOut();
150
                            });
151
                          }
152

  
81 153
                    </script>
82 154
                    </div>
83 155
                  </ul>
modules/dnet-openaire-users/trunk/src/main/webapp/js/validation.js
6 6
    var password_conf = $("#password_conf").val();
7 7

  
8 8
    var isValidEmail = validateEmail(email);
9
    var isValidPassword = validatePassword(password);
9 10
    var hasError = false;
10 11
    var isEmailFilled = false;
11 12
    var isPasswordFilled = false;
......
121 122
        }
122 123

  
123 124
        if(isPasswordFilled) {
124
                // Check if passwords match
125
                if (!confirm(password, password_conf)) {
126
                    $("#password").addClass('uk-input aai-form-danger');
127
                    $("#password_conf").addClass('uk-input aai-form-danger');
128
                    $(".msg_pass_conf_error").show();
129
            	    hasError = true;
130
                } else {
131
            	    $(".msg_pass_conf_error").hide();
132
                }
125
            // Check if passwords match
126
            if (!confirm(password, password_conf)) {
127
                $("#password").addClass('uk-input aai-form-danger');
128
                $("#password_conf").addClass('uk-input aai-form-danger');
129
                $(".msg_pass_conf_error").show();
130
                hasError = true;
131
            } else {
132
                $(".msg_pass_conf_error").hide();
133 133
            }
134
        }
135

  
136
        if(!isValidPassword) {
137
            $("#password").addClass('uk-input aai-form-danger');
138
            $(".msg_please_add").show();
139
            $(".msg_lowercase_letter").show();
140
            $(".msg_capital_letter").show();
141
            $(".msg_number").show();
142
            $(".msg_lenght").show();
143
            hasError = true;
144
        } else {
145
            $("#password").removeClass('aai-form-danger');
146
            $(".msg_please_add").hide();
147
            $(".msg_lowercase_letter").hide();
148
            $(".msg_capital_letter").hide();
149
            $(".msg_number").hide();
150
            $(".msg_lenght").hide();
151
        }
134 152
    }
135 153

  
136 154
    return !hasError;
......
141 159
    return re.test(email);
142 160
}
143 161

  
162
function validatePassword(password) {
163
    var pattern = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}$/;
164
    return pattern.test(password);
165
}
166

  
144 167
function confirm(first, second) {
145 168
    if (first == second)
146 169
        return true;

Also available in: Unified diff