implement log in as an api
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
define([
|
||||
'/bower_components/scrypt-async/scrypt-async.min.js',
|
||||
], function () {
|
||||
var Cred = {};
|
||||
var Scrypt = window.scrypt;
|
||||
|
||||
var isString = Cred.isString = function (x) {
|
||||
return typeof(x) === 'string';
|
||||
};
|
||||
|
||||
var isValidUsername = Cred.isValidUsername = function (name) {
|
||||
return !!(name && isString(name));
|
||||
};
|
||||
|
||||
var isValidPassword = Cred.isValidPassword = function (passwd) {
|
||||
return !!(passwd && isString(passwd));
|
||||
};
|
||||
|
||||
var passwordsMatch = Cred.passwordsMatch = function (a, b) {
|
||||
return isString(a) && isString(b) && a === b;
|
||||
};
|
||||
|
||||
var deriveFromPassphrase = Cred.deriveFromPassphrase = function
|
||||
(username, password, len, cb) {
|
||||
Scrypt(password,
|
||||
username,
|
||||
8, // memoryCost (n)
|
||||
1024, // block size parameter (r)
|
||||
len || 128, // dkLen
|
||||
200, // interruptStep
|
||||
cb,
|
||||
undefined); // format, could be 'base64'
|
||||
};
|
||||
|
||||
var dispenser = Cred.dispenser = function (bytes) {
|
||||
var entropy = {
|
||||
used: 0,
|
||||
};
|
||||
|
||||
// crypto hygeine
|
||||
var consume = function (n) {
|
||||
// explode if you run out of bytes
|
||||
if (entropy.used + n > bytes.length) {
|
||||
throw new Error('exceeded available entropy');
|
||||
}
|
||||
if (typeof(n) !== 'number') { throw new Error('expected a number'); }
|
||||
if (n <= 0) {
|
||||
throw new Error('expected to consume a positive number of bytes');
|
||||
}
|
||||
|
||||
// grab an unused slice of the entropy
|
||||
var A = bytes.slice(entropy.used, entropy.used + n);
|
||||
|
||||
// account for the bytes you used so you don't reuse bytes
|
||||
entropy.used += n;
|
||||
|
||||
//console.info("%s bytes of entropy remaining", bytes.length - entropy.used);
|
||||
return A;
|
||||
};
|
||||
|
||||
return consume;
|
||||
};
|
||||
|
||||
return Cred;
|
||||
});
|
||||
@@ -1,13 +1,13 @@
|
||||
define([
|
||||
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
||||
'/bower_components/chainpad-listmap/chainpad-listmap.js',
|
||||
'/bower_components/chainpad-crypto/crypto.js',
|
||||
'/common/cryptpad-common.js',
|
||||
'credential.js',
|
||||
'/common/credential.js',
|
||||
'/common/login.js',
|
||||
'/bower_components/tweetnacl/nacl-fast.min.js',
|
||||
'/bower_components/scrypt-async/scrypt-async.min.js', // better load speed
|
||||
'/bower_components/jquery/dist/jquery.min.js',
|
||||
], function (Config, Listmap, Crypto, Cryptpad, Cred) {
|
||||
], function (Listmap, Crypto, Cryptpad, Cred, Login) {
|
||||
var $ = window.jQuery;
|
||||
var Nacl = window.nacl;
|
||||
|
||||
@@ -16,6 +16,7 @@ define([
|
||||
var APP = window.APP = {
|
||||
Cryptpad: Cryptpad,
|
||||
Crypto: Crypto,
|
||||
Login: Login,
|
||||
};
|
||||
|
||||
// login elements
|
||||
|
||||
Reference in New Issue
Block a user