SetAccountPassword: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server function}} | {{Server function}} | ||
This function sets the password of the specified account. | |||
==Syntax== | ==Syntax== | ||
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd --> | <!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd --> | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool setAccountPassword(account theAccount, string password) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type --> | <!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type --> | ||
*''' | *'''theAccount:''' the account whos password you want to set | ||
*'''password:''' the password | |||
*''' | |||
===Returns=== | ===Returns=== | ||
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | <!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check --> | ||
Returns ''true'' if | Returns ''true'' if the password was set corrently, ''false'' otherwise. | ||
==Example== | ==Example== | ||
<!-- Explain what the example is in a single sentance --> | <!-- Explain what the example is in a single sentance --> | ||
This example | This example allows a user to change their password with a command. | ||
<!-- 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) | ||
-- get the account the player is currently logged into | |||
-- | local account = getClientAccount(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(getPlayerUserName(player),oldpass) | |||
if (oldpass==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 | |||
addCommandHandler("changepass",ChangePlayerPassword) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Account functions}} | {{Account functions}} | ||
Revision as of 15:47, 12 February 2008
This function sets the password of the specified account.
Syntax
bool setAccountPassword(account theAccount, string password)
Required Arguments
- theAccount: the account whos password you want to set
- password: the password
Returns
Returns true if the password was set corrently, false otherwise.
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 = getClientAccount(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(getPlayerUserName(player),oldpass) if (oldpass==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 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