-
Notifications
You must be signed in to change notification settings - Fork 8
/
authenticator.js
45 lines (42 loc) · 1022 Bytes
/
authenticator.js
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
const settings = require('electron-settings');
const sha256 = require('sha256');
const {remote} = require('electron');
module.exports = {
isPasswordCorrect:function (pass) {
var ps=settings.get('user.pass');
if(ps===null || !ps || !ps.length){
return false;
}
var hashedPs=hash(pass);
if(ps!=hashedPs)
{
return false;
}
return true;
},
savePassword:function (pass) {
var ps=pass;
settings.set('user', {
pass: hash(ps)
});
settings.set('firstAccess', {
value: 1
});
},
firstTimeAccess:function () {
if(settings.has('firstAccess.value') && settings.get('firstAccess.value')==1 )
{
return false;
}
return true;
},
resetThePass:function () {
remote.getGlobal("clearCache")();
settings.set('firstAccess', {
value: 0
});
}
}
function hash(val) {
return sha256(val);
}