Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update PasswordGenerator.ts to fix safeCharacterSet and use removeAmbigiousCharacters if option is enabled (#1404)

Leendert de Borstd1560347f0f5
diff --git a/apps/browser-extension/src/utils/dist/core/password-generator/index.js b/apps/browser-extension/src/utils/dist/core/password-generator/index.js
index bf5e27681..757060daa 100644
--- a/apps/browser-extension/src/utils/dist/core/password-generator/index.js
+++ b/apps/browser-extension/src/utils/dist/core/password-generator/index.js
@@ -192,25 +192,25 @@ var PasswordGenerator = class {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
return password;
@@ -218,26 +218,11 @@ var PasswordGenerator = class {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- getSafeCharacterSet(charSet, isAlpha) {
+ getSafeCharacterSet(charSet) {
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
- let charToRemove = ambChar;
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
- safeSet = safeSet.replace(charToRemove, "");
- }
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**
* Add a character from the given set at a random position in the password.
diff --git a/apps/browser-extension/src/utils/dist/core/password-generator/index.mjs b/apps/browser-extension/src/utils/dist/core/password-generator/index.mjs
index 9eaa3caa5..60016fcf9 100644
--- a/apps/browser-extension/src/utils/dist/core/password-generator/index.mjs
+++ b/apps/browser-extension/src/utils/dist/core/password-generator/index.mjs
@@ -166,25 +166,25 @@ var PasswordGenerator = class {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
return password;
@@ -192,26 +192,11 @@ var PasswordGenerator = class {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- getSafeCharacterSet(charSet, isAlpha) {
+ getSafeCharacterSet(charSet) {
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
- let charToRemove = ambChar;
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
- safeSet = safeSet.replace(charToRemove, "");
- }
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**
* Add a character from the given set at a random position in the password.
diff --git a/apps/mobile-app/utils/dist/core/password-generator/index.js b/apps/mobile-app/utils/dist/core/password-generator/index.js
index bf5e27681..757060daa 100644
--- a/apps/mobile-app/utils/dist/core/password-generator/index.js
+++ b/apps/mobile-app/utils/dist/core/password-generator/index.js
@@ -192,25 +192,25 @@ var PasswordGenerator = class {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
return password;
@@ -218,26 +218,11 @@ var PasswordGenerator = class {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- getSafeCharacterSet(charSet, isAlpha) {
+ getSafeCharacterSet(charSet) {
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
- let charToRemove = ambChar;
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
- safeSet = safeSet.replace(charToRemove, "");
- }
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**
* Add a character from the given set at a random position in the password.
diff --git a/apps/mobile-app/utils/dist/core/password-generator/index.mjs b/apps/mobile-app/utils/dist/core/password-generator/index.mjs
index 9eaa3caa5..60016fcf9 100644
--- a/apps/mobile-app/utils/dist/core/password-generator/index.mjs
+++ b/apps/mobile-app/utils/dist/core/password-generator/index.mjs
@@ -166,25 +166,25 @@ var PasswordGenerator = class {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
return password;
@@ -192,26 +192,11 @@ var PasswordGenerator = class {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- getSafeCharacterSet(charSet, isAlpha) {
+ getSafeCharacterSet(charSet) {
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
- let charToRemove = ambChar;
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
- safeSet = safeSet.replace(charToRemove, "");
- }
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**
* Add a character from the given set at a random position in the password.
diff --git a/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.js b/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.js
index bf5e27681..757060daa 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.js
+++ b/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.js
@@ -192,25 +192,25 @@ var PasswordGenerator = class {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
return password;
@@ -218,26 +218,11 @@ var PasswordGenerator = class {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- getSafeCharacterSet(charSet, isAlpha) {
+ getSafeCharacterSet(charSet) {
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
- let charToRemove = ambChar;
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
- safeSet = safeSet.replace(charToRemove, "");
- }
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**
* Add a character from the given set at a random position in the password.
diff --git a/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.mjs b/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.mjs
index 9eaa3caa5..60016fcf9 100644
--- a/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.mjs
+++ b/apps/server/AliasVault.Client/wwwroot/js/dist/core/password-generator/index.mjs
@@ -166,25 +166,25 @@ var PasswordGenerator = class {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
return password;
@@ -192,26 +192,11 @@ var PasswordGenerator = class {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- getSafeCharacterSet(charSet, isAlpha) {
+ getSafeCharacterSet(charSet) {
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
- let charToRemove = ambChar;
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
- safeSet = safeSet.replace(charToRemove, "");
- }
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**
* Add a character from the given set at a random position in the password.
diff --git a/core/typescript/password-generator/src/utils/PasswordGenerator.ts b/core/typescript/password-generator/src/utils/PasswordGenerator.ts
index 117e09c8a..5e5681832 100644
--- a/core/typescript/password-generator/src/utils/PasswordGenerator.ts
+++ b/core/typescript/password-generator/src/utils/PasswordGenerator.ts
@@ -200,28 +200,28 @@ export class PasswordGenerator {
if (this.useLowercase && !/[a-z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.lowercaseChars, true)
+ this.getSafeCharacterSet(this.lowercaseChars)
);
}
if (this.useUppercase && !/[A-Z]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.uppercaseChars, true)
+ this.getSafeCharacterSet(this.uppercaseChars)
);
}
if (this.useNumbers && !/\d/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.getSafeCharacterSet(this.numberChars, false)
+ this.getSafeCharacterSet(this.numberChars)
);
}
if (this.useSpecial && !/[!@#$%^&*()_+\-=[\]{}|;:,.<>?]/.exec(password)) {
password = this.addCharacterFromSet(
password,
- this.specialChars
+ this.getSafeCharacterSet(this.specialChars)
);
}
@@ -231,34 +231,13 @@ export class PasswordGenerator {
/**
* Get a character set with ambiguous characters removed if needed.
*/
- private getSafeCharacterSet(charSet: string, isAlpha: boolean): string {
+ private getSafeCharacterSet(charSet: string): string {
// If we're not using non-ambiguous characters, just return the original set.
if (!this.useNonAmbiguous) {
return charSet;
}
- let safeSet = charSet;
- for (const ambChar of this.ambiguousChars) {
- // For numeric sets, only process numeric ambiguous characters
- if (!isAlpha && !/\d/.test(ambChar)) {
- continue;
- }
-
- let charToRemove = ambChar;
-
- // Handle case conversion for alphabetic characters.
- if (isAlpha) {
- if (charSet === this.lowercaseChars) {
- charToRemove = ambChar.toLowerCase();
- } else {
- charToRemove = ambChar.toUpperCase();
- }
- }
-
- safeSet = safeSet.replace(charToRemove, '');
- }
-
- return safeSet;
+ return this.removeAmbiguousCharacters(charSet);
}
/**