Jump to content

passwordVerify problem ..


Marshell

Recommended Posts

 Hello!

Bad argument @ passwordVerify  [ Expected string at argument 2, got boolean]

Thanks in advance.

 

local MINIMUM_PASSWORD_LENGTH = 6
 
 
 local function isPasswordValid(password)
     return string.len(password) >= MINIMUM_PASSWORD_LENGTH
 end
 
 
 -- create an account
 addEvent('auth:register-attempt', true)
 addEventHandler('auth:register-attempt', root, function (username, password)
     -- check if an account with that username already exists
     if getAccount(username) then
         return outputChatBox('An account already exists with that name.', source, 255, 100, 100)
     end
 
 
     -- is the password valid?
     if not isPasswordValid(password) then
         return outputChatBox('The password supplied was not valid.', source, 255, 100, 100)
     end
 
 
     -- create a hash of the password
     local player = source
     passwordHash(password, 'bcrypt', {}, function (hashedPassword)
         -- create the account
         local account = addAccount(username, hashedPassword)
         setAccountData(account, 'hashed_password', hashedPassword)
 
 
         -- automatically login and spawn the player.
         logIn(player, account, hashedPassword)
         spawnPlayer(player, 0, 0, 10)
         setCameraTarget(player, player)
 
 
         return triggerClientEvent(player, 'register-menu:close', player)
     end)
 end)
 
 
 -- login to their account
 addEvent('auth:login-attempt', true)
 addEventHandler('auth:login-attempt', root, function (username, password)
 
 
     local account = getAccount(username)
     if not account then
         return outputChatBox('No such account could be found with that username or password.', source, 255, 100, 100)
     end
 
 
     local hashedPassword = getAccountData(account, 'hashed_password')
     local player = source
     passwordVerify(password, hashedPassword, function (isValid)        <<<< THIS IS THE LINE
         if not isValid then
             return outputChatBox('No such account could be found with that username or password.', player, 255, 100, 100)
         end
 
 
         if logIn(player, account, hashedPassword) then
             spawnPlayer(player, 0, 0, 10)
             setCameraTarget(player, player)
            return triggerClientEvent(player, 'login-menu:close', player)
         end
 
 
         return outputChatBox('An unknown error occured while attempting to authenticate.', player, 255, 100, 100)
     end)
 
 
 end)
 
 
 -- logout of their account
 addCommandHandler('accountLogout', function (player)
     logOut(player)
 end)
 

Link to comment
Just now, Shux said:

I'd guess the account you're attempting to sign in with doesn't have the data key "hashed_password" set to it. So you need to check if the data is found before you attempt to verify the password.

How can I do this ? can you tell me, please?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...