mirror of
				https://github.com/KevinMidboe/zoff.git
				synced 2025-10-29 18:00:23 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			25 lines
		
	
	
		
			703 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			25 lines
		
	
	
		
			703 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
// app/models/user.js
 | 
						|
// load the things we need
 | 
						|
var mongoose = require('mongoose');
 | 
						|
var bcrypt   = require('bcrypt-nodejs');
 | 
						|
 | 
						|
// define the schema for our user model
 | 
						|
var userSchema = mongoose.Schema({
 | 
						|
      username     : String,
 | 
						|
      password     : String,
 | 
						|
});
 | 
						|
 | 
						|
// methods ======================
 | 
						|
// generating a hash
 | 
						|
userSchema.methods.generateHash = function(password) {
 | 
						|
    return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
 | 
						|
};
 | 
						|
 | 
						|
// checking if password is valid
 | 
						|
userSchema.methods.validPassword = function(password) {
 | 
						|
    return bcrypt.compareSync(password, this.password);
 | 
						|
};
 | 
						|
 | 
						|
// create the model for users and expose it to our app
 | 
						|
module.exports = mongoose.model('User', userSchema);
 |