1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-25 02:04:15 +02:00

replacing bcrypt with bcryptjs

This commit is contained in:
Braun Patrik 2017-07-11 09:01:59 +02:00
parent cbfd0f32dc
commit cca4ceead0
7 changed files with 15 additions and 13 deletions

View File

@ -136,7 +136,8 @@ export class AuthenticationMWs {
sharingKey: req.query.sk || req.params.sharingKey,
});
if (!sharing || sharing.expires < Date.now() ||
(Config.Client.Sharing.passwordProtected === true && sharing.password && !PasswordHelper.comparePassword(password, sharing.password))) {
(Config.Client.Sharing.passwordProtected === true
&& sharing.password && !PasswordHelper.comparePassword(password, sharing.password))) {
return next(new Error(ErrorCodes.CREDENTIAL_NOT_FOUND));
}

View File

@ -1,12 +1,12 @@
import * as bcrypt from "bcrypt";
import * as bcrypt from "bcryptjs";
export class PasswordHelper {
public static async cryptPassword(password) {
const salt = await bcrypt.genSalt(10);
return await bcrypt.hash(password, salt);
public static cryptPassword(password) {
const salt = bcrypt.genSaltSync(10);
return bcrypt.hashSync(password, salt);
}
public static async comparePassword(password, encryptedPassword) {
return bcrypt.compare(password, encryptedPassword);
public static comparePassword(password, encryptedPassword) {
return bcrypt.compareSync(password, encryptedPassword);
}
}

View File

@ -57,7 +57,7 @@ export class UserManager implements IUserManager {
const users = await this.db.get("users");
let i = users.length;
while (i--) {
if (pass && !(await PasswordHelper.comparePassword(pass, users[i].password))) {
if (pass && !(PasswordHelper.comparePassword(pass, users[i].password))) {
users.splice(i, 1);
continue;
}
@ -72,7 +72,7 @@ export class UserManager implements IUserManager {
user.id = parseInt(this.db.get("idCounter")) + 1;
this.db.put("idCounter", user.id);
let users = this.db.get("users");
user.password = await PasswordHelper.cryptPassword(user.password);
user.password = PasswordHelper.cryptPassword(user.password);
users.push(user);
this.db.put("users", users);

View File

@ -89,7 +89,7 @@ export class MySQLConnection {
if (admins.length == 0) {
let a = new UserEntity();
a.name = "admin";
a.password = await PasswordHelper.cryptPassword("admin");
a.password = PasswordHelper.cryptPassword("admin");
a.role = UserRoles.Admin;
await userRepository.persist(a);
}

View File

@ -31,7 +31,7 @@ export class SharingManager implements ISharingManager {
await this.removeExpiredLink();
const connection = await MySQLConnection.getConnection();
if (sharing.password) {
sharing.password = await PasswordHelper.cryptPassword(sharing.password);
sharing.password = PasswordHelper.cryptPassword(sharing.password);
}
return await connection.getRepository(SharingEntity).persist(sharing);

View File

@ -43,7 +43,7 @@ export class UserManager implements IUserManager {
if (user.permissions && user.permissions != null) {
user.permissions = <any>JSON.stringify(<any>user.permissions);
}
user.password = await PasswordHelper.cryptPassword(user.password);
user.password = PasswordHelper.cryptPassword(user.password);
return await connection.getRepository(UserEntity).persist(user);
}

View File

@ -24,7 +24,8 @@
"url": "https://github.com/bpatrik/PiGallery2/issues"
},
"dependencies": {
"bcrypt": "^1.0.2",
"@types/bcryptjs": "^2.4.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.17.2",
"ejs": "^2.5.6",
"exif-parser": "^0.1.11",