UserManager.ts 795 B

123456789101112131415161718192021222324252627
  1. import {BaseEntityManager} from "../modules/DbCrafty/BaseEntityManager";
  2. import crypto = require('crypto');
  3. import {isUndefined} from "util";
  4. export class UserManager extends BaseEntityManager {
  5. public checkIfUserExist(username, password, fc) {
  6. if (!isUndefined(password))
  7. this.findOne({username: username, password: UserManager.hash(password)}, fc);
  8. else
  9. fc(null);
  10. }
  11. public insertNewUser(user) {
  12. user.nbAccess = 1;
  13. user.totalAccess = 0;
  14. user.password = UserManager.hash(user.password);
  15. this.saveEntity(user);
  16. }
  17. private static hash(pass) {
  18. console.log(pass);
  19. let passHash = crypto.pbkdf2Sync(pass, 'monSel', 5000, 512, 'sha512');
  20. return passHash.toString('hex');
  21. }
  22. }