if (empty($password)) { array_push($errors, "Password cannot be blank"); } if (count($errors) == 0) { $stmt = $conn->query("SELECT email, password_digest FROM users \n WHERE email='{$email}'"); # Bind values to the SQL query $result = $stmt->fetch_assoc(); if (count($result) > 0) { # Create digest of password $digest = encrypt_password($password); # Verify that the digest matches with the one stored in the DB if ($digest === $result["password_digest"]) { # Start a session for the user and store an auth_token $_SESSION["email"] = $email; $auth_token = substr(md5(microtime()), rand(0, 26), 15); set_auth_token($email, $auth_token, $conn); header("Location: index.php"); } else { $incorrect_password = "******"; array_push($errors, $incorrect_password); } } else { $user_not_found_err = "The email that you've entered does not match any account. Please register before continuing."; array_push($user_not_found_err); } } } var_dump($errors); ?> <!DOCTYPE html>
} if (empty($password)) { array_push($errors, "Password cannot be blank"); } if (empty($password_confirmation)) { array_push($errors, "Password confirmation cannot be blank"); } if ($password != $password_confirmation) { array_push($errors, "Password and confirmation do not match."); } if (count($errors) == 0) { $password_digest = encrypt_password($password); try { $stmt = $conn->query("INSERT INTO users(first_name, last_name, email, password_digest) \n VALUES('{$first_name}', '{$last_name}', '{$email}', '{$password_digest}')"); $auth_token = generate_auth_token(); set_auth_token($username, $auth_token, $conn); } catch (PDOException $e) { array_push($errors, $e->getMessage()); } } } var_dump($errors); ?> <!DOCTYPE html> <html> <head> <title> Login | UTEP Alumni Store </title> <?php require_once '_stylesheets.php'; ?>