diff options
author | Rob Kendrick (trite) <rjek@rjek.com> | 2013-07-30 16:33:36 +0100 |
---|---|---|
committer | Rob Kendrick (trite) <rjek@rjek.com> | 2013-07-30 16:33:36 +0100 |
commit | 81314dab9e280a6f944deef9bb9f8d61ac960454 (patch) | |
tree | e2516417aa4dd2ae4389d8d29a985fdf39b4b113 | |
parent | 33fb309807262347fdd8a2e3a4818dd4f1602065 (diff) | |
download | lua-scrypt-81314dab9e280a6f944deef9bb9f8d61ac960454.tar.gz |
Add example and 'minimal' test
-rw-r--r-- | example.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/example.lua b/example.lua new file mode 100644 index 0000000..a38f811 --- /dev/null +++ b/example.lua @@ -0,0 +1,30 @@ +local scrypt = require "scrypt" + +local curtime = 0; + +local function time(m) + curtime = os.clock() - curtime; + io.stdout:write(m, ": ",curtime, "\n") +end + +local hash1 = scrypt.hash_password("Hello", 2^14, 8, 1) +time "Generate hash1" +local hash2 = scrypt.hash_password("Hello", 2^14, 8, 1) +time "Generate hash2" + +assert(hash1 ~= hash2) -- hashes are salted + +local hash3 = scrypt.hash_password("Hello", 2^16, 8, 1) +time "Generate hash3" + +assert(scrypt.verify_password(hash1, "Hello")) +time "Verify hash1 with correct password" + +assert(scrypt.verify_password(hash2, "World") == false) +time "Verify hash2 with incorrect password" + +assert(scrypt.verify_password(hash3, "Hello")) +time "Verify hash3 with correct password" + +assert(scrypt.verify_password(hash3, "World") == false) +time "Verify hash3 with incorrect password" |