Commit d62d8c7d by tdgiang

Add bcryptjs password hashing lib and AdminUser model

Add passwordHash utility module wrapping bcryptjs for secure password hashing, and AdminUser Mongoose model with username (unique, lowercase), passwordHash, role (admin/staff), and active fields.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
parent 8cfa1225
"use strict";
var bcrypt = require("bcryptjs");
function hash(plain) {
return bcrypt.hashSync(plain, 10);
}
function compare(plain, hashed) {
return bcrypt.compareSync(plain, hashed);
}
module.exports = {
hash: hash,
compare: compare,
};
"use strict";
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var AdminUserSchema = new Schema(
{
username: { type: String, required: true, unique: true, lowercase: true, trim: true },
passwordHash: { type: String, required: true },
role: { type: String, enum: ["admin", "staff"], default: "staff" },
active: { type: Boolean, default: true },
},
{ timestamps: true }
);
module.exports = mongoose.model("AdminUser", AdminUserSchema);
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"hasInstallScript": true, "hasInstallScript": true,
"dependencies": { "dependencies": {
"async": "^2.0.1", "async": "^2.0.1",
"bcryptjs": "^3.0.3",
"body-parser": "^1.9.3", "body-parser": "^1.9.3",
"bunyan": "^1.8.1", "bunyan": "^1.8.1",
"chalk": "^0.5.1", "chalk": "^0.5.1",
...@@ -491,6 +492,15 @@ ...@@ -491,6 +492,15 @@
"tweetnacl": "^0.14.3" "tweetnacl": "^0.14.3"
} }
}, },
"node_modules/bcryptjs": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-3.0.3.tgz",
"integrity": "sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==",
"license": "BSD-3-Clause",
"bin": {
"bcrypt": "bin/bcrypt"
}
},
"node_modules/binary-extensions": { "node_modules/binary-extensions": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz",
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
}, },
"dependencies": { "dependencies": {
"async": "^2.0.1", "async": "^2.0.1",
"bcryptjs": "^3.0.3",
"body-parser": "^1.9.3", "body-parser": "^1.9.3",
"bunyan": "^1.8.1", "bunyan": "^1.8.1",
"chalk": "^0.5.1", "chalk": "^0.5.1",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment