Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@
"passwordEnterCurrent": "Please enter your current password",
"passwordEnterNew": "Please enter your new password",
"passwordError": "Password must only contain letters, numbers and symbols",
"passwordErrorLength": "Password must be between 6 and 64 characters long",
"passwordErrorLength": "Password must be between {min} and {max} characters long",
"passwordErrorMatch": "Passwords do not match",
"passwordFailed": "Failed to set password",
"passwordIncorrect": "Incorrect password",
Expand Down
4 changes: 2 additions & 2 deletions ts/session/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const PASSWORD_LENGTH = {
*/
MIN_PASSWORD_LEN: 6,
/**
* 64 chars
* 256 chars
*/
MAX_PASSWORD_LEN: 64,
MAX_PASSWORD_LEN: 256,
};
6 changes: 3 additions & 3 deletions ts/test/session/unit/utils/Password_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ describe('Password Util', () => {
});
});

it('should return an error if password is not between 6 and 64 characters', () => {
const invalid = ['a', 'abcde', '#'.repeat(65), '#'.repeat(100)];
it('should return an error if password is not between 6 and 256 characters', () => {
const invalid = ['a', 'abcde', '#'.repeat(257), '#'.repeat(300)];
invalid.forEach(pass => {
assert.strictEqual(
PasswordUtil.validatePassword(pass),
'Password must be between 6 and 64 characters long'
'Password must be between 6 and 256 characters long'
);
});
});
Expand Down
9 changes: 7 additions & 2 deletions ts/util/passwordUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ export const generateHash = (phrase: string) => phrase && sha512(phrase);
export const matchesHash = (phrase: string | null, hash: string) =>
phrase && sha512(phrase) === hash;

const passwordArgs = {
min: PASSWORD_LENGTH.MIN_PASSWORD_LEN.toString(),
max: PASSWORD_LENGTH.MAX_PASSWORD_LEN.toString(),
};

export const validatePassword = (phrase: string) => {
if (!isString(phrase)) {
return tr('passwordError');
}

if (phrase.length === 0) {
return tr('passwordErrorLength');
return tr('passwordErrorLength', passwordArgs);
}

if (
phrase.length < PASSWORD_LENGTH.MIN_PASSWORD_LEN ||
phrase.length > PASSWORD_LENGTH.MAX_PASSWORD_LEN
) {
return tr('passwordErrorLength');
return tr('passwordErrorLength', passwordArgs);
}

// Restrict characters to letters, numbers and symbols
Expand Down
Loading