This script provides validation of user login form inputs, comparison of user authorization data from the input with the one set in the database for this user, and starting a session with set parameters of 'user_id' and 'admin'.
More...
|
if(isset($error) && $error==="db_access_failed") | $email = $_POST['email'] ?? '' |
|
| $password = $_POST['password'] ?? '' |
|
| $emailPattern = "/^[a-z0-9.]+@[a-z0-9.]+\.[a-z0-9]{2,8}$/" |
|
| $passwordPattern = "/^(?=.*[0-9])(?=.*[!@#$%^&*-_])[a-zA-Z0-9!@#$%^&*-_]{8,32}$/" |
|
if(!preg_match($emailPattern, $email)||!preg_match($passwordPattern, $password)) | try |
|
| $user = $stmt->fetch(PDO::FETCH_ASSOC) |
|
if(! $user||!password_verify( $password, $user[ 'password'])) catch(PDOException $e) | $_SESSION ["user_id"] = $user['id'] |
|
| $_SESSION ["admin"] = $user['admin'] |
|
| $pdo = null |
|
This script provides validation of user login form inputs, comparison of user authorization data from the input with the one set in the database for this user, and starting a session with set parameters of 'user_id' and 'admin'.
Terminates and redirects back to the form page with error context parameter and all the user inputs except passwords as parameters of the redirecting GET request in case of error of data validation or database communication.