Skip to content

revised version of the code for better readability. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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();