Commit e81e0f67 authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Added a slightly better password generator

Make sure all error boxes are 300 wide
parent cb9d4c3b
......@@ -440,6 +440,7 @@ uxAjaxRequest = function(theWindow,config) {
Ext.Msg.show({
title: title,
msg: msg,
width: 300,
icon: Ext.MessageBox.ERROR,
fn: function() {
if (theWindow) {
......
......@@ -18,16 +18,54 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
/* Generate a random password */
/* Generate a random secure password - minimum length 8 */
function getRandomPass(len) {
var keylist="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"
var ret=''
var pass = '';
// Required keys
var lowers = 'abcdefghjkmnpqrstuvwxyz';
pass += lowers.charAt( Math.floor(Math.random() * lowers.length) );
var uppers = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
pass += uppers.charAt( Math.floor(Math.random() * uppers.length) );
var numbers = '23456789';
pass += numbers.charAt( Math.floor(Math.random() * numbers.length) );
var symbols = '!@#%^*()_+=[]?';
pass += symbols.charAt( Math.floor(Math.random() * symbols.length) );
// Keys, combined
var chars = lowers+uppers+numbers+symbols;
// Fill in remaining characters
var rem = 4;
if (len > 8) {
rem = len - 4;
}
for (i = 0; i < rem; i++) {
pass += chars.charAt( Math.floor(Math.random() * chars.length) );
}
// Return shuffled string
return shuffleString(pass);
}
for (i = 0; i < len; i++)
ret += keylist.charAt( Math.floor(Math.random() * keylist.length) )
/* Shuffle a string */
function shuffleString(str) {
// String to array
var a = str.split(""),
n = a.length;
// Array shuffle
for (var i = n - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
return ret
// Join and return
return a.join("");
}
/* Similar to php isset */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment