Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated to use Crypto

  • Loading branch information...
commit e0ed62dcdf853f7736d1088e7a3d50d5527f8884 1 parent c6ac52d
@mikevalstar authored
Showing with 25 additions and 8 deletions.
  1. +14 −1 addUser.js
  2. +10 −1 lib/AdminPages.js
  3. +1 −6 lib/Database.js
View
15 addUser.js
@@ -1,6 +1,15 @@
/**********************
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();
@@ -8,10 +17,14 @@ 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>");
View
11 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 = {
@@ -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){
View
7 lib/Database.js
@@ -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);
- }
+
};
Please sign in to comment.
Something went wrong with that request. Please try again.