diff options
author | Richard Ipsum <richardipsum@fastmail.co.uk> | 2014-01-21 12:47:50 +0000 |
---|---|---|
committer | Richard Ipsum <richard.ipsum@codethink.co.uk> | 2014-01-23 13:58:11 +0000 |
commit | 7430e995f7edefc69f9e0e4b99eb30a1a1a79080 (patch) | |
tree | 34a426cd9c5fba676739ae8f7bf70766d699bcdb | |
parent | c5c86235cd7616939dad1bac086e958c1f7529ff (diff) | |
download | gitano-7430e995f7edefc69f9e0e4b99eb30a1a1a79080.tar.gz |
Add hash_password and check_password to util
-rw-r--r-- | lib/gitano/util.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/gitano/util.lua b/lib/gitano/util.lua index 51c5bc2..b855bbd 100644 --- a/lib/gitano/util.lua +++ b/lib/gitano/util.lua @@ -9,9 +9,22 @@ local luxio = require 'luxio' local sio = require 'luxio.simple' local log = require 'gitano.log' +local scrypt = require 'scrypt' local tconcat = table.concat +local function hash_password(passwd) + -- We prepend the name of the hash function here + -- we may decide to use other hash functions in the future + -- so it's useful to provide some way to identify which hash + -- function was used + return 'scrypt:' .. scrypt.hash_password(passwd, 2^14, 8, 1) +end + +local function check_password(passwd, passwd_hash) + return scrypt.verify_password(passwd_hash, passwd) +end + local function _deep_copy(t, memo) if not memo then memo = {} end if memo[t] then return memo[t] end @@ -480,4 +493,7 @@ return { process_expansion = process_expansion, set = set, + + hash_password = hash_password, + check_password = check_password, } |