|
|
@ -146,19 +146,13 @@ class Auth_Internal extends Auth_Base {
|
|
|
|
|
|
|
|
|
|
|
|
function check_password(int $owner_uid, string $password, string $service = '') {
|
|
|
|
function check_password(int $owner_uid, string $password, string $service = '') {
|
|
|
|
|
|
|
|
|
|
|
|
if (get_schema_version() > 87) {
|
|
|
|
$user = ORM::for_table('ttrss_users')->find_one($owner_uid);
|
|
|
|
$sth = $this->pdo->prepare("SELECT login,pwd_hash,salt FROM ttrss_users WHERE id = ?");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$sth = $this->pdo->prepare("SELECT login,pwd_hash FROM ttrss_users WHERE id = ?");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sth->execute([$owner_uid]);
|
|
|
|
if ($user) {
|
|
|
|
|
|
|
|
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
$salt = $user['salt'] ?? "";
|
|
|
|
|
|
|
|
$login = $user['login'];
|
|
|
|
$salt = $row['salt'] ?? "";
|
|
|
|
$pwd_hash = $user['pwd_hash'];
|
|
|
|
$login = $row['login'];
|
|
|
|
|
|
|
|
$pwd_hash = $row['pwd_hash'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list ($pwd_algo, $raw_hash) = explode(":", $pwd_hash, 2);
|
|
|
|
list ($pwd_algo, $raw_hash) = explode(":", $pwd_hash, 2);
|
|
|
|
|
|
|
|
|
|
|
@ -194,33 +188,31 @@ class Auth_Internal extends Auth_Base {
|
|
|
|
$new_salt = UserHelper::get_salt();
|
|
|
|
$new_salt = UserHelper::get_salt();
|
|
|
|
$new_password_hash = UserHelper::hash_password($new_password, $new_salt, UserHelper::HASH_ALGOS[0]);
|
|
|
|
$new_password_hash = UserHelper::hash_password($new_password, $new_salt, UserHelper::HASH_ALGOS[0]);
|
|
|
|
|
|
|
|
|
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_users SET
|
|
|
|
$user = ORM::for_table('ttrss_users')->find_one($owner_uid);
|
|
|
|
pwd_hash = ?, salt = ?, otp_enabled = false
|
|
|
|
|
|
|
|
WHERE id = ?");
|
|
|
|
$user->salt = $new_salt;
|
|
|
|
$sth->execute([$new_password_hash, $new_salt, $owner_uid]);
|
|
|
|
$user->pwd_hash = $new_password_hash;
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
|
|
if ($_SESSION["uid"] ?? 0 == $owner_uid)
|
|
|
|
if ($_SESSION["uid"] ?? 0 == $owner_uid)
|
|
|
|
$_SESSION["pwd_hash"] = $new_password_hash;
|
|
|
|
$_SESSION["pwd_hash"] = $new_password_hash;
|
|
|
|
|
|
|
|
|
|
|
|
$sth = $this->pdo->prepare("SELECT email, login FROM ttrss_users WHERE id = ?");
|
|
|
|
if ($user->email) {
|
|
|
|
$sth->execute([$owner_uid]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
|
|
|
|
$mailer = new Mailer();
|
|
|
|
$mailer = new Mailer();
|
|
|
|
|
|
|
|
|
|
|
|
$tpl = new Templator();
|
|
|
|
$tpl = new Templator();
|
|
|
|
|
|
|
|
|
|
|
|
$tpl->readTemplateFromFile("password_change_template.txt");
|
|
|
|
$tpl->readTemplateFromFile("password_change_template.txt");
|
|
|
|
|
|
|
|
|
|
|
|
$tpl->setVariable('LOGIN', $row["login"]);
|
|
|
|
$tpl->setVariable('LOGIN', $user->login);
|
|
|
|
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
|
|
|
|
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
|
|
|
|
|
|
|
|
|
|
|
|
$tpl->addBlock('message');
|
|
|
|
$tpl->addBlock('message');
|
|
|
|
|
|
|
|
|
|
|
|
$tpl->generateOutputToString($message);
|
|
|
|
$tpl->generateOutputToString($message);
|
|
|
|
|
|
|
|
|
|
|
|
$mailer->mail(["to_name" => $row["login"],
|
|
|
|
$mailer->mail(["to_name" => $user->login,
|
|
|
|
"to_address" => $row["email"],
|
|
|
|
"to_address" => $user->email,
|
|
|
|
"subject" => "[tt-rss] Password change notification",
|
|
|
|
"subject" => "[tt-rss] Password change notification",
|
|
|
|
"message" => $message]);
|
|
|
|
"message" => $message]);
|
|
|
|
|
|
|
|
|
|
|
@ -244,21 +236,22 @@ class Auth_Internal extends Auth_Base {
|
|
|
|
$test_hash = UserHelper::hash_password($password, $salt, $pwd_algo);
|
|
|
|
$test_hash = UserHelper::hash_password($password, $salt, $pwd_algo);
|
|
|
|
|
|
|
|
|
|
|
|
if (hash_equals("$pwd_algo:$raw_hash", $test_hash)) {
|
|
|
|
if (hash_equals("$pwd_algo:$raw_hash", $test_hash)) {
|
|
|
|
$usth = $this->pdo->prepare("UPDATE ttrss_app_passwords SET last_used = NOW() WHERE id = ?");
|
|
|
|
$pass = ORM::for_table('ttrss_app_passwords')->find_one($row["id"]);
|
|
|
|
$usth->execute([$row['id']]);
|
|
|
|
$pass->last_used = 'NOW()';
|
|
|
|
|
|
|
|
|
|
|
|
if ($pwd_algo != UserHelper::HASH_ALGOS[0]) {
|
|
|
|
if ($pwd_algo != UserHelper::HASH_ALGOS[0]) {
|
|
|
|
// upgrade password to current algo
|
|
|
|
// upgrade password to current algo
|
|
|
|
Logger::log(E_USER_NOTICE, "Upgrading app password of user $login to " . UserHelper::HASH_ALGOS[0]);
|
|
|
|
Logger::log(E_USER_NOTICE, "Upgrading app password of user $login to " . UserHelper::HASH_ALGOS[0]);
|
|
|
|
|
|
|
|
|
|
|
|
$new_hash = UserHelper::hash_password($password, $salt, UserHelper::HASH_ALGOS[0]);
|
|
|
|
$new_hash = UserHelper::hash_password($password, $salt);
|
|
|
|
|
|
|
|
|
|
|
|
if ($new_hash) {
|
|
|
|
if ($new_hash) {
|
|
|
|
$usth = $this->pdo->prepare("UPDATE ttrss_app_passwords SET pwd_hash = ? WHERE id = ?");
|
|
|
|
$pass->pwd_hash = "$new_hash:$salt";
|
|
|
|
$usth->execute(["$new_hash:$salt", $row['id']]);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pass->save();
|
|
|
|
|
|
|
|
|
|
|
|
return $row['uid'];
|
|
|
|
return $row['uid'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|