function test_validPassword() { $result = PasswordUtils::testPassword("longPasswordlongPassword"); $this->assertEquals($result, "Password cannot be longer than 20 characters."); $result = PasswordUtils::testPassword("password"); $this->assertEquals($result, "Password must have at least one number."); $result = PasswordUtils::testPassword("123456789"); $this->assertEquals($result, "Password must have at least one letter."); }
function passwordError($password, $confirm) { $this->badPassword = PasswordUtils::testPassword($password); if (empty($password)) { $this->noPassword = "******"; } if (empty($confirm)) { $this->noConfirmPassword = "******"; } if ($password != $confirm && empty($this->noPassword) && empty($this->noConfirmPassword) && empty($this->badPassword)) { $this->noPasswordMatch = "Passwords do not match."; } }
die("Redirecting to index.php"); } else { if (!empty($_POST) && $changer->checkFieldsCorrect($_POST)) { $query = "\n SELECT *\n FROM users\n WHERE\n email = :email\n "; $query_params = array(':email' => $user['email']); try { $stmt = $db->prepare($query); $result = $stmt->execute($query_params); } catch (PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); } $row = $stmt->fetch(); if ($row) { $check_password = PasswordUtils::hashPassword($_POST['current_password'], $row['salt']); if (PasswordUtils::checkMatchingPasswords($check_password, $row['password'])) { $changer->errorMessage = PasswordUtils::testPassword($_POST['new_password']); if (empty($changer->errorMessage)) { $changer->makePasswordChange($db, $_POST['new_password'], $row['salt'], $row['id']); $changer->success = "Password changed successfully."; } } else { $changer->errorMessage = "Incorrect password."; } } } } ?> <!doctype html> <html lang="en"> <head>