-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Disallow repeating last 5 passwords.
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.
- Loading branch information
Showing
11 changed files
with
168 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { UnleashError } from './unleash-error'; | ||
|
||
export class PasswordPreviouslyUsed extends UnleashError { | ||
statusCode = 400; | ||
|
||
constructor( | ||
message: string = `You've previously used this password, please use a new password`, | ||
) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ test('Should require email or username', async () => { | |
test('should set password_hash for user', async () => { | ||
const store = stores.userStore; | ||
const user = await store.insert({ email: '[email protected]' }); | ||
await store.setPasswordHash(user.id, 'rubbish'); | ||
await store.setPasswordHash(user.id, 'rubbish', 5); | ||
const hash = await store.getPasswordHash(user.id); | ||
|
||
expect(hash).toBe('rubbish'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters