Last active
April 12, 2022 11:52
-
-
Save palpich/8341f4fb0dd9af421bd39ff6870eed4c to your computer and use it in GitHub Desktop.
Simple password generate
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
| function generatePassword(length: number) { | |
| const dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | |
| const array = new Uint8Array(length); | |
| self.crypto.getRandomValues(array); | |
| let password = '' | |
| for (var i = 0; i < array.length; i++) { | |
| password += dict.charAt(array[i] % dict.length) | |
| } | |
| return password | |
| } | |
| console.log(generatePassword(5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment