lua-bcrypt

Secure password hashing for Lua
Log | Files | Refs | README | LICENSE

tune.lua (438B)


      1 #! /usr/bin/lua
      2 
      3 local bcrypt = require( "bcrypt" )
      4 
      5 function bcrypt.tune( t )
      6 	local SAMPLES = 10
      7 	local rounds = 5
      8 
      9 	while true do
     10 		local total = 0
     11 
     12 		for i = 1, SAMPLES do
     13 			local start = os.clock()
     14 			bcrypt.digest( "asdf", rounds )
     15 			local delta = os.clock() - start
     16 
     17 			total = total + delta
     18 		end
     19 
     20 		if ( total / SAMPLES ) * 1000 >= t then
     21 			return rounds - 1
     22 		end
     23 
     24 		rounds = rounds + 1
     25 	end
     26 end
     27 
     28 print( bcrypt.tune( 250 ) )