Marshell Posted November 5, 2019 Share Posted November 5, 2019 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
justn Posted November 5, 2019 Share Posted November 5, 2019 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. Link to comment
Marshell Posted November 6, 2019 Author Share Posted November 6, 2019 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
justn Posted November 6, 2019 Share Posted November 6, 2019 local hashedPassword = getAccountData(account, 'hashed_password') if hashedPassword then Then you attempt to verify the password. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now