summaryrefslogtreecommitdiff
path: root/example.lua
blob: a600ad7a75b93c0b1dd72f75c7c0a03c6b2710e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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^15, 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"

local hash4 = scrypt.hash_password("Hello")
time "Generate hash 4, default N/r/p"