You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Server-side plugin for modella. Supports auto-salting, password hashing (using pbkdf2) and authentication.
Example
varmodella=require('modella');varauth=require('modella-auth');// Create modelvarUser=modella('user').attr('id').attr('email').attr('pass');// Use middlewareUser.use(auth({password: 'pass'}));// creatingUser.email('a@b.com').pass('secretz').save(function(err,res){user.pass()// salted passworduser.salt()// hash})// after submitting a formUser.authenticate(id,body.password,function(err,user){if(err)// something went wrongelseif(!user)// wrong passwordelse// all good!})// or authenticate an existing userUser.findOne({email: 'a@b.com'},function(err,model){User.authenticate(model,'1234',function(err,model){if(err)// something went wrongelseif(!user)// wrong passwordelse// all good!});});
API
auth(opts)
Initialize auth with the following options:
opts.password: the password attribute to lookup (default: password)
opts.salt: the salt attribute to use as a hash (default: salt)
auth introduces the following methods to your modella models:
Model#authenticate(id, password, fn)
Find your model with id and confirm it with your password. fn will return the model if the given credentials are correct, false if your credentials are wrong, or an err if something bad happened.