This repository was archived by the owner on Nov 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoUtils.js
More file actions
80 lines (62 loc) · 1.32 KB
/
oUtils.js
File metadata and controls
80 lines (62 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(function (thiz) {
var O = thiz.O;
O.expand({
charMatrix: {
lcase: [97,122],
ucase: [65,90],
nums: [48,57],
symb: [33,33,35,47,58,64,91,96,123,126],
space: [161,254]
},
passGenerator: function (chars,n) {
var str = "", v;
for (var j in chars) {
var M = O.charMatrix[j];
for (var u=0;u<M.length;u+=2) {
for (var y=M[u];y<=M[u+1];y++) {
str += String.fromCharCode(y);
}
}
}
var pass = '';
if (str) {
var l = str.length,
p = 0;
for (p=0;p<n;) {
v = Math.floor(Math.random() * l);
if (v == l) continue;
var c = str.substring(v,v+1);
pass += c;
p++;
}
}
return pass;
},
simplePassGenerator: function (n) {
return O.passGenerator({
lcase: 1,
ucase: 1,
nums: 1
},n?n:16);
},
genRandomKey: function (x, salt, nohex) {
var l = x && x < 64 ? x : 64,
ret = O.salthash(
O.passGenerator({
lcase: 1,
ucase: 1,
nums: 1,
symb: 1,
space: 1
},256),'',salt, nohex)
.substring(0,l);
return ret;
},
salthash: function (str,n,salt,nohex) {
if (!salt) for (var j=0;j<str.length;j++) salt += str.charCodeAt(j);
var ss = O.toSHA256(salt+str);
if (n) ss = ss.substring(0,n);
return nohex ? O.toStr(ss) : ss;
}
});
})(this);