summaryrefslogtreecommitdiff
path: root/classes/userhelper.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-15 16:59:54 +0300
committerAndrew Dolgov <[email protected]>2021-02-15 16:59:54 +0300
commit39604bedef15b7d56c23ce101d5e74a93bc5620c (patch)
treec006b95ddbcfa89794c414c4e4cb0a007d125e45 /classes/userhelper.php
parent5d42ce553faa3a3eb2a12d66c9b0870ad778c163 (diff)
move reset_password to UserHelper
Diffstat (limited to 'classes/userhelper.php')
-rw-r--r--classes/userhelper.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/classes/userhelper.php b/classes/userhelper.php
index 744f77a23..8e9b9a01b 100644
--- a/classes/userhelper.php
+++ b/classes/userhelper.php
@@ -169,4 +169,34 @@ class UserHelper {
session_commit();
}
+ static function reset_password($uid, $format_output = false) {
+
+ $pdo = Db::pdo();
+
+ $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?");
+ $sth->execute([$uid]);
+
+ if ($row = $sth->fetch()) {
+
+ $login = $row["login"];
+
+ $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $tmp_user_pwd = make_password();
+
+ $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
+
+ $sth = $pdo->prepare("UPDATE ttrss_users
+ SET pwd_hash = ?, salt = ?, otp_enabled = false
+ WHERE id = ?");
+ $sth->execute([$pwd_hash, $new_salt, $uid]);
+
+ $message = T_sprintf("Changed password of user %s to %s", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>");
+
+ if ($format_output)
+ print_notice($message);
+ else
+ print $message;
+
+ }
+ }
}