Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Не могу авторизоваться логин или пароль неправильный
- Файл обработчика формы
- include 'classes/Login.php';
- include 'classes/Database.php';
- $pdo = Database::connection();
- $login = new Login($pdo);
- // Input from the user
- $email = $_POST['email'];
- $password = $_POST['password'];
- // If email is correct
- if ($login->verifyEmail($email)){
- $user = $login->verifyEmail($email);
- // If password is correct
- if ($login->verifyPassword($user, $password)){
- $message = "Welcome!";
- //echo "<script type='text/javascript'>alert('$message');</script>";
- $url='userpage.php';
- echo '<META HTTP-EQUIV=REFRESH CONTENT="1; '.$url.'">';
- }
- else {
- $message = "Wrong password or email";
- echo "<script type='text/javascript'>alert('$message');</script>";
- $url='login.php';
- echo '<META HTTP-EQUIV=REFRESH CONTENT="1; '.$url.'">';
- }
- }
- else {
- header("Location: login.php");
- }
- Файл класса Login
- class Login {
- private $pdo;
- public function __construct($pdo)
- {
- session_start();
- $this->pdo = $pdo;
- }
- // Check if email exists
- public function verifyEmail($email){
- $stmt = $this->pdo->prepare("SELECT * FROM users WHERE email = :email LIMIT 1");
- $stmt->bindParam(':email', $email);
- $stmt->execute();
- $user = $stmt->fetch();
- return $user;
- }
- // Verify password
- function verifyPassword($user, $password){
- $email = $user['email'];
- $hash = $user['password'];
- $id = $user['id'];
- $isAdmin = $user['isAdmin'];
- if(password_verify($password, $hash)){
- $_SESSION['loggedIn'] = true;
- $_SESSION['email'] = $email;
- $_SESSION['id'] = $id;
- if($isAdmin == 1){
- $_SESSION['isAdmin'] = true;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement