Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions Nodejs API/utils/password-hash.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
/*
* Real time private chatting app using Angular 2, Nodejs, mongodb and Socket.io
* @author Shashank Tiwari
*/
'use strict';
const bcrypt = require('bcrypt');

class PasswordHash{
class PasswordHash {
constructor() {
this.saltRounds = 10; // Number of salt rounds for hashing
}

createHash(password) {
return bcrypt.hashSync(password, 10);
}
async createHash(password) {
try {
const salt = await bcrypt.genSalt(this.saltRounds);
return await bcrypt.hash(password, salt);
} catch (error) {
throw new Error('Error creating hash');
}
}

compareHash(password, hash) {
return bcrypt.compareSync(password, hash)
}
async compareHash(password, hash) {
try {
return await bcrypt.compare(password, hash);
} catch (error) {
throw new Error('Error comparing hash');
}
}
}

module.exports = new PasswordHash();