“您必须输入密码,至少包含一个小写数字和一个符号“ Java EE

问题描述 投票:0回答:1

我想加强用户注册时的密码要求。

我在servlet Registration.java中编写了以下代码:

  public static boolean checkpassword(password){
        boolean hasNum = false; boolean hasCap = false; boolean hasLow = false; char c; 
        for (int i = 0; i< password.length();i++)
        {
            c = password.charAt(i);
            if (Character.isDigit(c))
            {
                hasNum = true;
            }
            else if (Character.isUpperCase(c)) {

                hasCap = true;
            }
            else if (Character.isLowerCase(c)){

                hasLow = true;
                                }
            else if (hasNum && hasCap && hasLow) {
                return true;
            }

        }
        return false;

    }

但是,我不知道将其放在下面的servlet中的位置:

public class Register extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String firstname = request.getParameter("firstname");
        String lastname = request.getParameter("lastname");
        String email = request.getParameter("email");
        String password = request.getParameter("password");
        String password1 = request.getParameter("password1");
        String country = request.getParameter("country");
        String city = request.getParameter("city");
        String address = request.getParameter("address");
        String postalcode = request.getParameter("postalcode");



        if (password == password1 && email.contains("@")) {

            try {
                Class.forName("org.sqlite.JDBC");
                Connection con = DriverManager
                    .getConnection("jdbc:sqlite:/Users/Oussama/login.db");
                PreparedStatement ps = con
                    .prepareStatement("insert into users values(?,?,?,?,?,?,?,?,?)");
                ps.setString(2, firstname);
                ps.setString(3, lastname);
                ps.setString(4, email);
                ps.setString(5, password);
                ps.setString(6, country);
                ps.setString(7, city);
                ps.setString(8, address);
                ps.setString(9, postalcode);

                int i = ps.executeUpdate();
                if (i > 0)
                    out.print("You are successfully registered...");

                } catch (Exception e2) {
                System.out.println(e2);
            }

            out.close();
        }

        else {
            request.setAttribute("errorMessage",
                "Passwords do not match");
            request.getRequestDispatcher("/register.jsp").forward(request,
                response);
        }
    }
}

我试图在之前和之后放置它,但是仍然有错误。

你们知道我将这组代码放在哪里吗(我认为这是可行的?)>

谢谢您!

我想加强用户注册时的密码要求。我在servlet Registration.java中编写了以下代码:public static boolean checkpassword(password){...

java function servlets
1个回答
0
投票

您检查密码强度的方法不完整。编写如下:

© www.soinside.com 2019 - 2024. All rights reserved.