UserManager.ts 765 B

1234567891011121314151617181920212223242526
  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 = 0;
  13. user.password = UserManager.hash(user.password);
  14. this.saveEntity(user);
  15. }
  16. private static hash(pass) {
  17. console.log(pass);
  18. let passHash = crypto.pbkdf2Sync(pass, 'monSel', 5000, 512, 'sha512');
  19. return passHash.toString('hex');
  20. }
  21. }