This commit is contained in:
Jay Trees 2022-03-23 10:32:21 +01:00
parent 2762ffaeee
commit 55e1d158d6
3 changed files with 17 additions and 6 deletions

View file

@ -12,6 +12,17 @@ namespace wishthis;
class User class User
{ {
/**
* Static
*/
public static function generatePassword(string $plainPassword): string
{
return sha1($plainPassword);
}
/**
* Non-Static
*/
public function __construct(int $id = -1) public function __construct(int $id = -1)
{ {
if (-1 === $id) { if (-1 === $id) {

View file

@ -6,7 +6,7 @@
* @author Jay Trees <github.jay@grandel.anonaddy.me> * @author Jay Trees <github.jay@grandel.anonaddy.me>
*/ */
use wishthis\{Page, Email}; use wishthis\{Page, Email, User};
$page = new Page(__FILE__, __('Login')); $page = new Page(__FILE__, __('Login'));
@ -15,7 +15,7 @@ $page = new Page(__FILE__, __('Login'));
*/ */
if (isset($_POST['login'], $_POST['email'], $_POST['password'])) { if (isset($_POST['login'], $_POST['email'], $_POST['password'])) {
$email = $_POST['email']; $email = $_POST['email'];
$password = sha1($_POST['password']); $password = User::generatePassword($_POST['password']);
$database->query('UPDATE `users` $database->query('UPDATE `users`
SET `last_login` = NOW() SET `last_login` = NOW()

View file

@ -6,7 +6,7 @@
* @author Jay Trees <github.jay@grandel.anonaddy.me> * @author Jay Trees <github.jay@grandel.anonaddy.me>
*/ */
use wishthis\Page; use wishthis\{Page, User};
$passwordReset = isset($_GET['password-reset'], $_GET['token']); $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']) { if (time() > $user['password_reset_valid_until']) {
$database $database
->query('UPDATE `users` ->query('UPDATE `users`
SET `password` = "' . sha1($_POST['password']) . '", SET `password` = "' . User::generatePassword($_POST['password']) . '",
`password_reset_token` = NULL, `password_reset_token` = NULL,
`password_reset_valid_until` = NULL `password_reset_valid_until` = NULL
WHERE `id` = ' . $user['id'] . ';'); WHERE `id` = ' . $user['id'] . ';');
@ -97,7 +97,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
`power` `power`
) VALUES ( ) VALUES (
"' . $_POST['email'] . '", "' . $_POST['email'] . '",
"' . sha1($_POST['password']) . '", "' . User::generatePassword($_POST['password']) . '",
100 100
) )
;'); ;');
@ -115,7 +115,7 @@ if (isset($_POST['email'], $_POST['password']) && !empty($_POST['planet'])) {
`password` `password`
) VALUES ( ) VALUES (
"' . $_POST['email'] . '", "' . $_POST['email'] . '",
"' . sha1($_POST['password']) . '" "' . User::generatePassword($_POST['password']) . '"
) )
;'); ;');
$userRegistered = true; $userRegistered = true;