Created
November 7, 2013 20:14
-
-
Save fritzy/7361109 to your computer and use it in GitHub Desktop.
Set password as sha1 hash and check password against hash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL "this script" 1 key userid password | |
local key = KEYS[1]; | |
local userid, pass = unpack(ARGV); | |
local hash = redis.sha1hex('SOME-STATIC-SALT'..string.sub(pass, 1, 2)..userid..string.sub(pass, 3)); | |
--no error, does hash match? | |
return {false, (redis.call('GET', key) == hash)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--EVAL "this script" 1 key userid password | |
local key = KEYS[1]; | |
local userid, pass = unpack(ARGV); | |
if (#pass < 8) then | |
--bytes, actually | |
return {"Password must be at least 8 characters."} | |
end | |
local hash = redis.sha1hex('SOME-STATIC-SALT'..string.sub(pass, 1, 2)..userid..string.sub(pass, 3)); | |
redis.call('SET', key, hash); | |
--no error | |
return {false}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment