Skip to content

Commit

Permalink
Updated to use Crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevalstar committed Jan 27, 2012
1 parent c6ac52d commit e0ed62d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
15 changes: 14 additions & 1 deletion addUser.js
@@ -1,17 +1,30 @@
/**********************
A simple script to add a new user
**********************/
// Includes
var crypto = require('crypto');

function hashString(value) {
hash = crypto.createHash('sha1');
hash.update(value);
return hash.digest('hex');
}

// Database
var Database = require('./lib/Database');
var db = new Database();
db.connect('mongodb://localhost/mv');

if(process.argv.length == 4){
// 0 will be node, 1 will be the script
db.addUser(process.argv[2], process.argv[3], function(err){

var au = db.model('adminUser');
var usr = new au({login: process.argv[2], password: hashString(process.argv[3]) });
usr.save(function(err){
console.log("User added to database");
process.exit(0); // Success
});

}else{
console.error("Script requires exactly 2 arguments");
console.error("Usage: node addUser.js <email> <password>");
Expand Down
11 changes: 10 additions & 1 deletion lib/AdminPages.js
@@ -1,3 +1,12 @@
// Includes
var crypto = require('crypto');

function hashString(value) {
hash = crypto.createHash('sha1');
hash.update(value);
return hash.digest('hex');
}

var AdminPages = module.exports = function AdminPages(){};

AdminPages.prototype = {
Expand Down Expand Up @@ -36,7 +45,7 @@ AdminPages.prototype = {
var adminuser = this.db.model('adminUser');
adminuser.findOne(
{ login: req.body.email
, password: req.body.password }
, password: hashString(req.body.password) }
, function(err, row){

if(err){
Expand Down
7 changes: 1 addition & 6 deletions lib/Database.js
Expand Up @@ -31,10 +31,5 @@ Database.prototype = {
return this._model.adminUser;
}
}

, addUser: function(email, pass, ret){
var au = this.model('adminUser');
var usr = new au({login: email, password: pass});
usr.save(ret);
}

};

0 comments on commit e0ed62d

Please sign in to comment.