Comments (2)
@mleanos The way the generator is built it could take forever to get to the password that matched that pattern. To allow that use case we would have to be able to parse the regexp and understand what should go next.
What you're doing on that regexp is basically telling what the password sequence should be, which could lead to a password like aa0? (\w+ could generate A or a)
You could use something like:
var generatePassword = require("password-generator");
var max = 15;
var min = 9;
var UPPERCASE_RE = /([A-Z])/g;
var LOWERCASE_RE = /([a-z])/g;
var NUMBER_RE = /([\d])/g;
var SPECIAL_CHAR_RE = /([\?\-])/g;
function isStrongEnough(password) {
var uc = password.match(UPPERCASE_RE);
var lc = password.match(LOWERCASE_RE);
var n = password.match(NUMBER_RE);
var sc = password.match(SPECIAL_CHAR_RE);
return uc && lc && n && sc && password.length >= min;
}
function customPassword() {
var password = "";
while (!isStrongEnough(password)) {
password = generatePassword(Math.floor(Math.random() * (max - min)) + min, false, /[\w\d\?\-]/);
}
return password;
}
console.log(customPassword());
I hope that helps you
from password-generator.
@bermi Thank you for your suggestion. I understand the limitations and I appreciate the example you provided. Others will surely benefit from it as well.
I went with a simplified version of your example. Rather than managing the requirements with the regular expression pattern matches, I'm using a package that was already implemented in the project for testing the strength.
Thanks much!
from password-generator.
Related Issues (20)
- A cryptographically secure PRNG (crypto.getRandomValues) should be used instead of Math.random HOT 2
- Old version in bower repo HOT 2
- memorable option should not disable pattern HOT 2
- Doesn't work in old versions of IE as claimed HOT 1
- algorithm behind HOT 1
- switch to minimist HOT 4
- [Request] Add support for angular HOT 3
- Request: Add support for random seed HOT 1
- Uniqueness HOT 2
- Generator never hits uppercase 'A' HOT 4
- Unable to generate a password with the tilde character HOT 1
- Don't use `Math.random` in example on README
- vulnerable dependency: yargs-parser HOT 1
- v2.3.x Do Not Handle Commandline Arguments HOT 3
- Missing dist folder in npm install or yarn 2.x
- How to make sure password contains both letters and characters HOT 3
- Hangs HOT 1
- RangeError: Maximum call stack size exceeded HOT 1
- Please add bower support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from password-generator.