diff --git a/src/classes/user.php b/src/classes/user.php index 975aa539..464e7a70 100644 --- a/src/classes/user.php +++ b/src/classes/user.php @@ -12,6 +12,17 @@ namespace wishthis; class User { + /** + * Static + */ + public static function generatePassword(string $plainPassword): string + { + return sha1($plainPassword); + } + + /** + * Non-Static + */ public function __construct(int $id = -1) { if (-1 === $id) { diff --git a/src/pages/login.php b/src/pages/login.php index ea55a92b..00fb3869 100644 --- a/src/pages/login.php +++ b/src/pages/login.php @@ -6,7 +6,7 @@ * @author Jay Trees */ -use wishthis\{Page, Email}; +use wishthis\{Page, Email, User}; $page = new Page(__FILE__, __('Login')); @@ -15,7 +15,7 @@ $page = new Page(__FILE__, __('Login')); */ if (isset($_POST['login'], $_POST['email'], $_POST['password'])) { $email = $_POST['email']; - $password = sha1($_POST['password']); + $password = User::generatePassword($_POST['password']); $database->query('UPDATE `users` SET `last_login` = NOW() diff --git a/src/pages/register.php b/src/pages/register.php index 6468ab49..1090010c 100644 --- a/src/pages/register.php +++ b/src/pages/register.php @@ -6,7 +6,7 @@ * @author Jay Trees */ -use wishthis\Page; +use wishthis\{Page, User}; $passwordReset = isset($_GET['password-reset'], $_GET['token']); @@ -70,7 +70,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { if (time() > $user['password_reset_valid_until']) { $database ->query('UPDATE `users` - SET `password` = "' . sha1($_POST['password']) . '", + SET `password` = "' . User::generatePassword($_POST['password']) . '", `password_reset_token` = NULL, `password_reset_valid_until` = NULL WHERE `id` = ' . $user['id'] . ';'); @@ -97,7 +97,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { `power` ) VALUES ( "' . $_POST['email'] . '", - "' . sha1($_POST['password']) . '", + "' . User::generatePassword($_POST['password']) . '", 100 ) ;'); @@ -115,7 +115,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) { `password` ) VALUES ( "' . $_POST['email'] . '", - "' . sha1($_POST['password']) . '" + "' . User::generatePassword($_POST['password']) . '" ) ;'); $userRegistered = true;