PHP verification username and password cannot be empty

藏色散人
Release: 2023-02-25 18:32:02
Original
6537 people have browsed it

PHP verification username and password cannot be empty

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");
Copy after login

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{
……
}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template