SetAccountPassword: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Добавление языков)
 
(21 intermediate revisions by 15 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server function}}
{{Server function}}
This function sets the password of the specified account.
This function sets the password of the specified [[account]].
{{note| Don't forget to give admin rights to the resource, in which you are using setAccountPassword function or it won't work.}}


==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 -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setAccountPassword(account theAccount, string password)
bool setAccountPassword ( account theAccount, string password )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[account]]:setPassword|password|}}
===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 -->
*'''theAccount:''' the account whose password you want to set
*'''theAccount:''' the account whos password you want to set
*'''password:''' the password
*'''password:''' the password
{{Note|The password will always be encrypted with '''sha256''', other types are no longer supported. See [https://github.com/multitheftauto/mtasa-blue/wiki/CAccountPassword CAccountPassword] for more information.}}


===Returns===
===Returns===
<!-- 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 the password was set correctly, ''false'' otherwise.
Returns ''true'' if the password was set corrently, ''false'' otherwise.
 
===Limits===
The following limits apply:
* Minimum account password length is 1 character.
* Maximum account password length is 30 characters.
* Account password can not be equal to "*****"


==Example==  
==Example==  
Line 23: Line 28:
<!-- 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 = getClientAccount(player)
local account = getPlayerAccount(player)
if (account) then
if (account) then
-- 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 35: Line 40:
-- check that the old password is correct
-- check that the old password is correct
local password_check = getAccount(getPlayerUserName(player),oldpass)
local password_check = getAccount(getAccountName(account), oldpass)
if (oldpass==password_check) then
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>


==See Also==
==See Also==
{{Account functions}}
{{Account functions}}
[[en:setAccountPassword]]
[[ru:setAccountPassword]]
[[ar:setAccountPassword]]
[[es:setAccountPassword]]
[[zh-cn:setAccountPassword]]

Latest revision as of 15:48, 12 April 2021

This function sets the password of the specified account.

[[{{{image}}}|link=|]] Note: Don't forget to give admin rights to the resource, in which you are using setAccountPassword function or it won't work.

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 whose password you want to set
  • password: the password
[[{{{image}}}|link=|]] Note: The password will always be encrypted with sha256, other types are no longer supported. See CAccountPassword for more information.

Returns

Returns true if the password was set correctly, false otherwise.

Limits

The following limits apply:

  • Minimum 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