20 lines
434 B
Nim
20 lines
434 B
Nim
import bcrypt
|
|
|
|
import ./configuration
|
|
import ./db
|
|
import ./models
|
|
|
|
proc randomString*(cost: int8): string = genSalt(cost)
|
|
|
|
proc hashPwd*(pwd: string, salt: string): string =
|
|
result = hash(pwd, salt)
|
|
|
|
proc hashPwd*(pwd: string, cost: int8): string =
|
|
let salt = genSalt(cost)
|
|
result = hash(pwd, salt)
|
|
|
|
proc validatePwd*(u: User, givenPwd: string): bool =
|
|
let salt = u.salt
|
|
result = compare(u.hashedPwd, hash(givenPwd, salt))
|
|
|