SetAccountPassword: Difference between revisions
Jump to navigation
Jump to search
m (fix oop syntax) |
|||
Line 25: | Line 25: | ||
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized --> | <!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized --> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function ChangePlayerPassword(player,command,oldpass,newpass) | function ChangePlayerPassword(player, command, oldpass, newpass) | ||
-- get the account the player is currently logged into | -- get the account the player is currently logged into | ||
local account = getPlayerAccount(player) | local account = getPlayerAccount(player) | ||
Line 31: | Line 31: | ||
-- if its only a guest account, do not allow the password to be changed | -- if its only a guest account, do not allow the password to be changed | ||
if (isGuestAccount(account)) then | if (isGuestAccount(account)) then | ||
outputChatBox("You must be logged into an account to change your password.",player) | outputChatBox("You must be logged into an account to change your password.", player) | ||
-- end the function | -- end the function | ||
return | return | ||
Line 37: | Line 37: | ||
-- check that the old password is correct | -- check that the old password is correct | ||
local password_check = getAccount( | local password_check = getAccount(getAccountName(account), oldpass) | ||
if ( | if (password_check) then | ||
-- check the length of the new password | -- check the length of the new password | ||
if (string.len(newpass)>=5) then | if (string.len(newpass)>=5) then | ||
setAccountPassword(account,newpass) | setAccountPassword(account,newpass) | ||
else | else | ||
outputChatBox("Your new password must be at least 5 characters long.",player) | outputChatBox("Your new password must be at least 5 characters long.", player) | ||
end | end | ||
else | else | ||
outputChatBox("Old password invalid.",player) | outputChatBox("Old password invalid.", player) | ||
end | end | ||
end | end | ||
end | |||
addCommandHandler("changepass",ChangePlayerPassword) | addCommandHandler("changepass", ChangePlayerPassword) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 16:49, 20 February 2015
This function sets the password of the specified account.
Syntax
bool setAccountPassword ( account theAccount, string password )
OOP Syntax Help! I don't understand this!
- Method: account:setPassword(...)
- Variable: .password
Required Arguments
- theAccount: the account whos password you want to set
- password: the password
Returns
Returns true if the password was set correctly, false otherwise.
Limits
- Minimal account password length is 1 character.
- Maximum account password length is 30 characters.
- Account password can not be equal to "*****"
Example
This example allows a user to change their password with a command.
function ChangePlayerPassword(player, command, oldpass, newpass) -- get the account the player is currently logged into local account = getPlayerAccount(player) if (account) then -- if its only a guest account, do not allow the password to be changed if (isGuestAccount(account)) then outputChatBox("You must be logged into an account to change your password.", player) -- end the function return end -- check that the old password is correct local password_check = getAccount(getAccountName(account), oldpass) if (password_check) then -- check the length of the new password if (string.len(newpass)>=5) then setAccountPassword(account,newpass) else outputChatBox("Your new password must be at least 5 characters long.", player) end else outputChatBox("Old password invalid.", player) end end end addCommandHandler("changepass", ChangePlayerPassword)
See Also
- addAccount
- copyAccountData
- getAccount
- getAccountData
- getAccountName
- getAccountPlayer
- getAccountSerial
- getAccounts
- getAccountsBySerial
- getAllAccountData
- getPlayerAccount
- isGuestAccount
- logIn
- logOut
- removeAccount
- setAccountData
- setAccountPassword
- getAccountByID
- getAccountID
- getAccountIP
- getAccountsByData
- getAccountsByIP
- setAccountName