1
0
mirror of https://github.com/S2-/pwgen.git synced 2025-08-02 08:50:04 +02:00

use crypto.getRandomValues

This commit is contained in:
s2
2017-11-21 09:30:54 +01:00
parent 8ab06aa554
commit 42838040d2

View File

@@ -3,10 +3,15 @@ function randPassword(length, includeSpecial) {
if (includeSpecial) { if (includeSpecial) {
pwdChars += '°^!"§$%&/()=?`´\\}][{²³€|<>-.,;:*+_µ@~'; pwdChars += '°^!"§$%&/()=?`´\\}][{²³€|<>-.,;:*+_µ@~';
} }
let randPassword = Array(length).fill(pwdChars).map(function(x) {
return x[Math.floor(Math.random() * x.length)] let randValues = new Uint32Array(length);
}).join(''); let randPwd = '';
return randPassword; window.crypto.getRandomValues(randValues);
for(i=0; i<length; i++)
{
randPwd += pwdChars[randValues[i] % pwdChars.length];
}
return randPwd;
} }
function getParams() { function getParams() {