basic outline of logins

pull/1/head
ansuz 8 years ago
parent 2968488278
commit 67baf30d65

@ -15,6 +15,13 @@
</style> </style>
</head> </head>
<body> <body>
<div data-localization="login_warning"></div>
<input type="text" name="username" id="username" data-localization-placeholder="login_username"><br />
<input type="password" name="password" id="password" data-localization-placeholder="login_password"><br />
<button id="login">login</button> <button id="login">login</button>
<input type="checkbox" name="remember" id="remember"><label for="remember" data-localization="login_remember"></label>

@ -15,91 +15,24 @@ define([
var secret = {}; var secret = {};
var module = window.APP = { var APP = window.APP = {
Cryptpad: Cryptpad, Cryptpad: Cryptpad,
Crypto: Crypto,
}; };
var print = function (S, t) { var print = function (S, t) {
$('body').append($('<' + (t || 'p') + '>').text(S)); $('body').append($('<' + (t || 'p') + '>').text(S));
}; };
var getInputs = function (cb) { var hashFromCreds = function (username, password, len, cb) {
Cryptpad.prompt("What is your username?", "", function (name) { Scrypt(password,
if (!name || typeof(name) !== 'string') { return cb('no name'); } username,
setTimeout(function () { 8, // memoryCost (n)
Cryptpad.prompt("What is your password?", "", function (pw) { 1024, // block size parameter (r)
if (!pw || typeof(pw) !== 'string') { return cb('no password'); } len || 128, // dkLen
cb(void 0, { 200, // interruptStep
password: pw, cb,
salt: name, undefined); // format, could be 'base64'
});
}, {
sensitive: true,
});
}, 1000);
});
};
var login = function (cb) {
getInputs(function (err, input) {
if (err) {
Cryptpad.alert(err);
return;
}
var time = +new Date();
Scrypt(input.password,
input.salt,
8, // memoryCost (n)
1024, // block size parameter (r)
128, // dkLen
undefined && 200, // interruptStep
function (S) {
print("Login took " + ((+new Date()) -time )+ "ms");
cb(S);
},
'base64');
});
};
var read = function (proxy) {
console.log("Proxy ready!");
var otime = +new Date(proxy.atime);
var atime = proxy.atime = ('' + new Date());
if (otime) {
print("Last visit was " +
(((+new Date(atime)) - otime) / 1000) +
" seconds ago");
}
proxy.ctime = proxy.ctime || atime;
proxy.schema = proxy.schema || 'login_data';
print(JSON.stringify(proxy, null, 2), 'pre');
};
var change = function (o, n, p) {
console.log("change at [%s] %s => %s", p.join(","), o, n);
};
var remove = function (o, p, root) {
console.log("removal at [%s]", p.join(','));
};
var ready = function (proxy, next) {
//console.log("umm");
proxy.on('ready', function (info) {
read(proxy);
proxy.on('change', [], change)
.on('remove', [], remove);
next();
})
.on('disconnect', function (info) {
});
}; };
var authenticated = function (password, next) { var authenticated = function (password, next) {
@ -130,11 +63,105 @@ define([
}); });
}; };
var useBytes = function (bytes) {
var firstSeed = bytes.slice(0, 18);
var secondSeed = bytes.slice(18, 35);
var remainder = bytes.slice(34);
var seed = {};
seed.keys = Crypto.createEditCryptor(null, firstSeed);
seed.keys.editKeyStr = seed.keys.editKeyStr.replace(/\//g, '-');
seed.channel = Cryptpad.uint8ArrayToHex(secondSeed);
console.log(seed);
var channelHex = seed.channel;
var channel64 = Cryptpad.hexToBase64(channelHex);
console.log(seed.keys.editKeyStr);
seed.editHash = Cryptpad.getEditHashFromKeys(channelHex, seed.keys.editKeyStr);
var secret = Cryptpad.getSecrets(seed.editHash);
console.log(secret);
console.log(seed.editHash);
//return;
var config = {
websocketURL: Cryptpad.getWebsocketURL(),
channel: channelHex,
data: {},
validateKey: seed.keys.validateKey || undefined,
readOnly: seed.keys && !seed.keys.editKeyStr,
crypto: Crypto.createEncryptor(seed.keys),
};
var rt = APP.rt = Listmap.create(config);
rt.proxy.on('create', function (info) {
console.log('created');
//console.log(info);
})
.on('ready', function (info) {
console.log('ready');
//console.log(info);
var proxy = rt.proxy;
var now = +(new Date());
if (!proxy.atime) {
console.log("first time visiting!");
proxy.atime = now;
} else {
console.log("last visit was %ss ago", (now - proxy.atime) / 1000);
proxy.atime = now;
}
console.log(proxy);
})
.on('disconnect', function (info) {
console.log('disconnected');
console.log(info);
});
};
var isValidUsername = function (name) {
return !!name;
};
var isValidPassword = function (passwd) {
return !!passwd;
};
var $username = $('#username');
var $password = $('#password');
0 && hashFromCreds('ansuz', 'pewpewpew', 128, useBytes);
$('#login').click(function () { $('#login').click(function () {
login(function (hash) { var uname = $username.val();
print('Your Key', 'h1'); var passwd = $password.val();
print(hash, 'pre');
authenticated(hash, ready); if (!isValidUsername(uname)) {
return void Cryptpad.alert('invalid username');
}
if (!isValidPassword(passwd)) {
return void Cryptpad.alert('invalid password');
}
$username.val("");
$password.val("");
// we need 18 bytes for the regular crypto
hashFromCreds(uname, passwd, 128, function (bytes) {
//console.log(bytes);
useBytes(bytes);
}); });
}); });
}); });

Loading…
Cancel
Save