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 60732fd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib/PasswordStrength.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ 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; }
// Count everything else that is not a lowercase letter as a symbol
else if (characters[i].match(/[^a-z]/)) { 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 60732fd

Please sign in to comment.