I wanted to make a simple practice website through which people can sign up and log in, to get to the page they desire.
when the user registers, the username and password gets salted and hashed through the use of passportLocalMongoose. It then gets added inside the database.
This is how the salted and hashed username and password looks like when added through the use of passportLocalMongoose.
{ "_id" : ObjectId("56ecb64ff2860fee176fb102"), "salt" : "f59b3e4bdd0c9081fdf84a227133d9cca2c40fdd1f304b23a786efd15e835a03", "hash" : "6ae24365b2001821253aaf62d9ad34cd5c80cc1bb369ad22701fd4f06e085c1bc32b6ffe3850bb38b23ee4947cc1dc078cd151e32de7f8a18d0bdf3732533a3c2a8ed91ec78a52fa74b266a933bc047fe2c6ab2708bfe6232ea1379069c73c154a3eaf4168aaa94d6a90f073cffbd651dd0ed5211850254832062da8b276d90efcfa59042189bab1833eef52d72ef827cd613429706d586292129221ddaed53747c51a4c92f820be98672975a400a75f49a9aa68ce6be7aa0a0b1c9de59a0004589959939ddaa06ae48b1d388ed985cb1f0b821d14039ace1448a48171d12cad04a812ec8c1716aef244afcfde0576161e1ab4ee43d58409d432068a9d716c840bff7b9cdf5a4fd04cebfb4cf1fdf23724bc4e436511e9b4510179fcaf22edb58f84ca1264773fb1df5c0e4a20298fbd9b240d5fb52008dfe443f88433f12c58b61489b7342093c873ee8bc233c570579621ec91970f01b79026d82da5f3710a3ba7be784f01a0fc49862043371e343921d544a4c50cf977ec34e5a951f5ab25523f968efe3d475927ff9cff6b6559afc2f11464b4e1b85d191ded29070488a4ad4af3d59217ce74b72afada062b7f7e81ca2da52d9e2f63bd67aff95b4578a062350f1e105a5a14899ebb59613e66d1a69b4b0b3389cb64f2400104d1b86f3838bc16091a86014d3ef3dd74dc4b910189fe7f6e63bfbf36a62d1ac8446f9f21", "username" : "John", "__v" : 0 }
What I want is to do the same thing without going through passportLocalMongoose. I would like to salt and hash username and password through the command line using mongod.
so like something like that
> use accounts
db.user.[something that salts and hashes]
I am sorry for some wrong use of terminology ("salted", "hashed") but I didnt know how else I could write it down.
I would like to add that when I do for example:
> use Accounts
>db.student.insert('username':'Mark', 'password':'1234')
And then when I try to log in through command line created username and password it give me "GET/ favicon.ico 500 post" error...
here is the code where it hashes(register):
router.post('/register', function(req, res, next) {
Account.register(new Account({ username : req.body.username }), req.body.password, function(err, account) {
if (err) {
return res.render("register", {info: "Sorry. That username already exists. Try again."});
}
passport.authenticate('local')(req, res, function () {
req.session.save(function (err) {
if (err) {
return next(err);
}
res.redirect('/');
});
});
});
});
and here is the code where the user tries to log in:
router.get('/login', function(req, res) {
console.log(Error);
res.render('login', { user : req.user, message : req.flash('error')});
});
router.post('/login', passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res, next) {
req.session.save(function (err) {
if (err) {
console.log("error maybe?");
return next(err);
}
console.log("not error maybe?")
res.redirect('/');
});
});
and this is my connection:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var passportLocalMongoose = require('passport-local-mongoose');
var Account = new Schema({
username: String,
password: String
});
Account.plugin(passportLocalMongoose);
module.exports = mongoose.model('accounts', Account);
Thank you all.