Skip to content

Instantly share code, notes, and snippets.

@fritzy
Created November 7, 2013 20:14
Show Gist options
  • Save fritzy/7361109 to your computer and use it in GitHub Desktop.
Save fritzy/7361109 to your computer and use it in GitHub Desktop.
Set password as sha1 hash and check password against hash.
--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)}
--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