Skip to content

Commit

Permalink
Treat non-ASCII characters as symbols in password strength calculation
Browse files Browse the repository at this point in the history
Before, any non-ASCII characters were simply ignored for password strength.
  • Loading branch information
sisou committed Jan 6, 2024
1 parent 5666de9 commit f6c9a22
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/lib/PasswordStrength.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ class PasswordStrength {

const baseScore = 30;

for (let i = 0; i < password.length; i++) {
if (password.charAt(i).match(/[A-Z]/g)) { count.upperCase += 1; }
if (password.charAt(i).match(/[0-9]/g)) { count.numbers += 1; }
if (password.charAt(i).match(/(.*[!,@,#,$,%,^,&,*,?,_,~])/)) { count.symbols += 1; }
const characters = [...password];
const length = characters.length;

for (let i = 0; i < length; i++) {
if (characters[i].match(/[A-Z]/g)) {
count.upperCase += 1;
} else if (characters[i].match(/[0-9]/g)) {
count.numbers += 1;
} else if (characters[i].match(/[^a-z]/)) {
// Count everything else that is not a lowercase letter as a symbol
count.symbols += 1;
}
}

count.excess = password.length - minLength;
count.excess = length - minLength;

if (count.upperCase && count.numbers && count.symbols) {
weight.combo = 25;
Expand Down

0 comments on commit f6c9a22

Please sign in to comment.