-
-
Save Uvacoder/e5c61b40df1d79b573c59544dbcef615 to your computer and use it in GitHub Desktop.
Generate random password
This file contains hidden or 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
| const CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}[]:;<>?/|\\'; | |
| function generatePassword(length = 12) { | |
| let pass = ''; | |
| for (let i = length; i > 0; --i) pass += CHARS[Math.floor(Math.random() * CHARS.length)]; | |
| return pass | |
| } | |
| // Usage: | |
| generatePassword(15) | |
| // > "hBI!A31Hs}(oIv*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment