Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Password reset/change accepting current password as new password (
#16331) Co-authored-by: Diego Sampaio <chinello@gmail.com>
- Loading branch information
1 parent
d46c864
commit d6a6332
Showing
5 changed files
with
54 additions
and
23 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
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,29 @@ | ||
import { Accounts } from 'meteor/accounts-base'; | ||
|
||
/** | ||
* 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 compareUserPassword(user, pass) { | ||
if (!user?.services?.password?.bcrypt?.trim()) { | ||
return true; | ||
} | ||
|
||
if (!pass || (!pass.plain && !pass.sha256)) { | ||
return false; | ||
} | ||
|
||
const password = pass.plain || { | ||
digest: pass.sha256.toLowerCase(), | ||
algorithm: 'sha-256', | ||
}; | ||
|
||
const passCheck = Accounts._checkPassword(user, password); | ||
|
||
if (passCheck.error) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
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