mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-18 11:14:57 +02:00
We'll store hashes for the last 5 passwords, fetch them all for the user wanting to change their password, and make sure the password does not verify against any of the 5 stored hashes. Includes some password-related UI/UX improvements and refactors. Also some fixes related to reset password rate limiting (instead of an unhandled exception), and token expiration on error. --------- Co-authored-by: Nuno Góis <github@nunogois.com>
16 lines
669 B
JavaScript
16 lines
669 B
JavaScript
exports.up = function(db, cb) {
|
|
db.runSql(`
|
|
CREATE TABLE used_passwords(user_id INTEGER REFERENCES users(id) ON DELETE CASCADE,
|
|
password_hash TEXT NOT NULL,
|
|
used_at TIMESTAMP WITH TIME ZONE DEFAULT (now() AT time zone 'utc'),
|
|
PRIMARY KEY (user_id, password_hash)
|
|
);
|
|
INSERT INTO used_passwords(user_id, password_hash) SELECT id, password_hash FROM users WHERE password_hash IS NOT NULL;
|
|
CREATE INDEX used_passwords_pw_hash_idx ON used_passwords(password_hash);
|
|
`, cb)
|
|
};
|
|
|
|
exports.down = function(db, cb) {
|
|
db.runSql(`DROP TABLE used_passwords;`, cb);
|
|
};
|