-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[NEW] Password history #21607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[NEW] Password history #21607
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
220c01e
Add password history setting and database entries
matheusbsilva137 d11c8eb
Add passwordHistory entries and block user from reusing passwords sto…
matheusbsilva137 3bfd74d
Update addPasswordToHistory to store passwords when the setting is di…
matheusbsilva137 ebb36d3
Update error messages and add translations
matheusbsilva137 b345b38
Merge branch 'develop' into password-history
matheusbsilva137 5cb79df
Fix error message and update digest assignment
matheusbsilva137 faf296b
Update digest assignment
matheusbsilva137 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| export interface IPassword { | ||
| plain?: string; | ||
| sha256?: string; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,46 @@ | ||
| import { Accounts } from 'meteor/accounts-base'; | ||
|
|
||
| import { IUser } from '../../definition/IUser'; | ||
| import { IPassword } from '../../definition/IPassword'; | ||
| import { settings } from '../../app/settings/server'; | ||
|
|
||
| /** | ||
| * Check if a given password is the one user by given user or if the user doesn't have a password | ||
| * @param {object} user User object | ||
| * @param {object} pass Object with { plain: 'plain-test-password' } or { sha256: 'sha256password' } | ||
| */ | ||
| export function compareUserPasswordHistory(user: IUser, pass: IPassword): boolean { | ||
| if (!user?.services?.passwordHistory || !settings.get('Accounts_Password_History_Enabled')) { | ||
| return true; | ||
| } | ||
|
|
||
| if (!pass || (!pass.plain && !pass.sha256) || !user?.services?.password?.bcrypt) { | ||
| return false; | ||
| } | ||
|
|
||
| const currentPassword = user.services.password.bcrypt; | ||
| const passwordHistory = user.services.passwordHistory.slice(-Number(settings.get('Accounts_Password_History_Amount'))); | ||
|
|
||
| for (const password of passwordHistory) { | ||
| if (!password.trim()) { | ||
| user.services.password.bcrypt = currentPassword; | ||
| return false; | ||
| } | ||
| user.services.password.bcrypt = password; | ||
|
|
||
| const historyPassword = pass.plain || { | ||
| digest: pass.sha256 ? pass.sha256.toLowerCase() : '', | ||
| algorithm: 'sha-256' as const, | ||
| }; | ||
|
|
||
| const passCheck = Accounts._checkPassword(user, historyPassword); | ||
|
|
||
| if (!passCheck.error) { | ||
| user.services.password.bcrypt = currentPassword; | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| user.services.password.bcrypt = currentPassword; | ||
|
KevLehman marked this conversation as resolved.
|
||
| return true; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.