argon2 experiment
This commit is contained in:
		@@ -5,7 +5,7 @@ local constants = require("constants")
 | 
			
		||||
 | 
			
		||||
local util = require("util")
 | 
			
		||||
 | 
			
		||||
local bcrypt = require("bcrypt")
 | 
			
		||||
local auth = require("lib.auth")
 | 
			
		||||
local rand = require("openssl.rand")
 | 
			
		||||
 | 
			
		||||
local models = require("models")
 | 
			
		||||
@@ -14,7 +14,7 @@ local Sessions = models.Sessions
 | 
			
		||||
local Avatars = models.Avatars
 | 
			
		||||
 | 
			
		||||
local function authenticate_user(user, password)
 | 
			
		||||
  return bcrypt.verify(password, user.password_hash)
 | 
			
		||||
  return auth.verify(password, user.password_hash)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function create_session_key()
 | 
			
		||||
@@ -321,7 +321,7 @@ app:post("user_signup", "/signup", function(self)
 | 
			
		||||
 | 
			
		||||
  local new_user = Users:create({
 | 
			
		||||
    username = username,
 | 
			
		||||
    password_hash = bcrypt.digest(password, constants.BCRYPT_ROUNDS),
 | 
			
		||||
    password_hash = auth.digest(password),
 | 
			
		||||
    permission = constants.PermissionLevel.GUEST,
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
local bcrypt = require("bcrypt")
 | 
			
		||||
local auth = require("lib.auth")
 | 
			
		||||
local models = require("models")
 | 
			
		||||
local constants = require("constants")
 | 
			
		||||
 | 
			
		||||
@@ -29,7 +29,7 @@ local function create_admin()
 | 
			
		||||
    password = password .. alphabet:sub(randi, randi)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  local hash = bcrypt.digest(password, constants.BCRYPT_ROUNDS)
 | 
			
		||||
  local hash = auth.digest(password)
 | 
			
		||||
 | 
			
		||||
  models.Users:create({
 | 
			
		||||
    username = username,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								lib/auth.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								lib/auth.lua
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
local auth = {}
 | 
			
		||||
 | 
			
		||||
local ls = require "luasodium"
 | 
			
		||||
 | 
			
		||||
function auth.digest(password)
 | 
			
		||||
  return ls.crypto_pwhash_str(
 | 
			
		||||
    password,
 | 
			
		||||
    ls.crypto_pwhash_OPSLIMIT_INTERACTIVE,
 | 
			
		||||
    ls.crypto_pwhash_MEMLIMIT_INTERACTIVE)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function auth.verify(password, hash)
 | 
			
		||||
  return ls.crypto_pwhash_str_verify(hash, password)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return auth
 | 
			
		||||
@@ -16,7 +16,7 @@ dependencies = {
 | 
			
		||||
  "lapis == 1.16.0",
 | 
			
		||||
  "lsqlite3",
 | 
			
		||||
  "magick",
 | 
			
		||||
  "bcrypt",
 | 
			
		||||
  "luasodium",
 | 
			
		||||
  "luaossl",
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user