php method to verify that the username and password cannot be empty
When doing the user registration and login section, I found that even if If you do not fill in the information in the registration form, a piece of data with empty username and password will be created in the database, and then you can log in with an empty username and password. This is obviously wrong.
Then I thought of determining whether at least one of the username and password is empty after the form is submitted. If one is empty, the request is forwarded to the registration page and the username and password are re-entered to register. When logging in, you must first determine whether the username and password are
and whether they are empty. Only when the username and password are both empty will the database be verified.
Determine whether the username and password are empty:
String username=request.getParameter("username"); String password=request.getParameter("password");
The username and password obtained here are both strings. Even if they are empty data, they are also ""empty strings , is not empty, so the judgment should be like this:
if(username==""||password==""){ request.setAttribute("error", "用户名或密码不能为空"); request.getRequestDispatcher("/view/login.jsp").forward(request,response); }else{ …… }
For more PHP knowledge, please visit PHP Chinese website!
The above is the detailed content of PHP verification username and password cannot be empty. For more information, please follow other related articles on the PHP Chinese website!