mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-17 08:17:59 +00:00
Forgotten file with password strength related functions
This commit is contained in:
parent
e555631b40
commit
921d16a458
1 changed files with 39 additions and 0 deletions
39
wizard/utils.js
Normal file
39
wizard/utils.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
.pragma library
|
||||
|
||||
// grabbed from SO answer page: http://stackoverflow.com/questions/948172/password-strength-meter
|
||||
|
||||
function scorePassword(pass) {
|
||||
var score = 0;
|
||||
if (!pass)
|
||||
return score;
|
||||
|
||||
// award every unique letter until 5 repetitions
|
||||
var letters = {};
|
||||
for (var i=0; i<pass.length; i++) {
|
||||
letters[pass[i]] = (letters[pass[i]] || 0) + 1;
|
||||
score += 5.0 / letters[pass[i]];
|
||||
}
|
||||
|
||||
// bonus points for mixing it up
|
||||
var variations = {
|
||||
digits: /\d/.test(pass),
|
||||
lower: /[a-z]/.test(pass),
|
||||
upper: /[A-Z]/.test(pass),
|
||||
nonWords: /\W/.test(pass),
|
||||
}
|
||||
|
||||
var variationCount = 0;
|
||||
for (var check in variations) {
|
||||
variationCount += (variations[check] === true) ? 1 : 0;
|
||||
}
|
||||
score += (variationCount - 1) * 10;
|
||||
|
||||
return parseInt(score);
|
||||
}
|
||||
|
||||
function mapScope (inputScopeFrom, inputScopeTo, outputScopeFrom, outputScopeTo, value) {
|
||||
var x = (value - inputScopeFrom) / (inputScopeTo - inputScopeFrom);
|
||||
var result = outputScopeFrom + ((outputScopeTo - outputScopeFrom) * x);
|
||||
return result;
|
||||
}
|
Loading…
Reference in a new issue