Created
December 21, 2016 07:02
-
-
Save RHavar/048b0465ba4b222631bd29512f6dadd7 to your computer and use it in GitHub Desktop.
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 randomPassword(len) { var chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNP123456789"; if (window && window.crypto && window.crypto.getRandomValues && Uint32Array && Uint32Array.prototype.reduce) { return window.crypto.getRandomValues(new Uint32Array(len)) .reduce(function(p, n) { return p + chars[n % chars.length] }, ""); } else { console.warn('Falling back to pseudo-random client seed'); var pass = ""; for (var i = 0; i < len; ++i) pass += chars[Math.floor(Math.random() * chars.length)]; return pass; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment