Created
November 2, 2018 09:32
-
-
Save Astargh/c3e3dde8e043a0bc1c6614a6d0477f09 to your computer and use it in GitHub Desktop.
Random password method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
randomPassword(length) { | |
const chars = 'abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890'; | |
let pass = ''; | |
for (let x = 0; x < length; x++) { | |
let i = Math.floor(Math.random() * chars.length); | |
pass += chars.charAt(i); | |
} | |
if (pass.match(/^(?=.*\d)(?=.*[^a-zA-Z\d\s:])(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,15}$/g) === null) { | |
return this.randomPassword(length); | |
} | |
return pass; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment