<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kaasis</id>
	<title>Multi Theft Auto: Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multitheftauto.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kaasis"/>
	<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/wiki/Special:Contributions/Kaasis"/>
	<updated>2026-05-05T14:03:44Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50771</id>
		<title>PasswordHash</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50771"/>
		<updated>2017-04-22T13:44:04Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function creates a new password hash using a specified hashing algorithm.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to hash.&lt;br /&gt;
*'''algorithm:''' The algorithm to use:&lt;br /&gt;
** ''bcrypt'': use the bcrypt hashing algorithm&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''options:''' table with options for the hashing algorithm, as detailed below&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Options for each hashing algorithm===&lt;br /&gt;
* ''bcrypt'':&lt;br /&gt;
** ''cost'' (int), default: 10.  Visit [http://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt this link] to determine the number of rounds appropriate for your server.&lt;br /&gt;
** ''salt'' (string), default: automatically generate salt &lt;br /&gt;
*** an empty string will automatically generate a salt with the ''cost'' provided&lt;br /&gt;
*** if a string is provided, the given salt is used (do not do this!)&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the hash as a string if hashing was successful, ''false'' otherwise. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Warning|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of [https://wiki.multitheftauto.com/wiki/PasswordHash passwordHash] and [https://wiki.multitheftauto.com/wiki/PasswordVerify passwordVerify] in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
* Use '''&amp;lt;/accountCreate [username] [password]&amp;gt;''' to create an account.&lt;br /&gt;
* Use '''&amp;lt;/accountLogin [username] [password]&amp;gt;''' to login in account.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword) -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
			if (account) then&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordVerify&amp;diff=50770</id>
		<title>PasswordVerify</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordVerify&amp;diff=50770"/>
		<updated>2017-04-22T13:43:49Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function verifies whether a password matches a password hash.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool passwordVerify ( string password, string hash[, function callback] )  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to check.&lt;br /&gt;
*'''hash:''' A supported hash (see [[passwordHash]])&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns true if the password matches the hash. Returns false if the password does not match, or if an unknown hash was passed. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Warning|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of [https://wiki.multitheftauto.com/wiki/PasswordHash passwordHash] and [https://wiki.multitheftauto.com/wiki/PasswordVerify passwordVerify] in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
* Use '''&amp;lt;/accountCreate [username] [password]&amp;gt;''' to create an account.&lt;br /&gt;
* Use '''&amp;lt;/accountLogin [username] [password]&amp;gt;''' to login in account.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword) -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
			if (account) then&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordVerify&amp;diff=50767</id>
		<title>PasswordVerify</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordVerify&amp;diff=50767"/>
		<updated>2017-04-22T13:33:07Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function verifies whether a password matches a password hash.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool passwordVerify ( string password, string hash[, function callback] )  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to check.&lt;br /&gt;
*'''hash:''' A supported hash (see [[passwordHash]])&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns true if the password matches the hash. Returns false if the password does not match, or if an unknown hash was passed. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Warning|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword) -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
			if (account) then&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50766</id>
		<title>PasswordHash</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50766"/>
		<updated>2017-04-22T13:32:40Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function creates a new password hash using a specified hashing algorithm.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to hash.&lt;br /&gt;
*'''algorithm:''' The algorithm to use:&lt;br /&gt;
** ''bcrypt'': use the bcrypt hashing algorithm&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''options:''' table with options for the hashing algorithm, as detailed below&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Options for each hashing algorithm===&lt;br /&gt;
* ''bcrypt'':&lt;br /&gt;
** ''cost'' (int), default: 10.  Visit [http://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt this link] to determine the number of rounds appropriate for your server.&lt;br /&gt;
** ''salt'' (string), default: automatically generate salt &lt;br /&gt;
*** an empty string will automatically generate a salt with the ''cost'' provided&lt;br /&gt;
*** if a string is provided, the given salt is used (do not do this!)&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the hash as a string if hashing was successful, ''false'' otherwise. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Warning|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword) -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
			if (account) then&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordVerify&amp;diff=50763</id>
		<title>PasswordVerify</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordVerify&amp;diff=50763"/>
		<updated>2017-04-22T12:48:43Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function verifies whether a password matches a password hash.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
bool passwordVerify ( string password, string hash[, function callback] )  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to check.&lt;br /&gt;
*'''hash:''' A supported hash (see [[passwordHash]])&lt;br /&gt;
&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns true if the password matches the hash. Returns false if the password does not match, or if an unknown hash was passed. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Warning|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword)&lt;br /&gt;
			if (account) then -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50762</id>
		<title>PasswordHash</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50762"/>
		<updated>2017-04-22T12:46:04Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function creates a new password hash using a specified hashing algorithm.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to hash.&lt;br /&gt;
*'''algorithm:''' The algorithm to use:&lt;br /&gt;
** ''bcrypt'': use the bcrypt hashing algorithm&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''options:''' table with options for the hashing algorithm, as detailed below&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Options for each hashing algorithm===&lt;br /&gt;
* ''bcrypt'':&lt;br /&gt;
** ''cost'' (int), default: 10.  Visit [http://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt this link] to determine the number of rounds appropriate for your server.&lt;br /&gt;
** ''salt'' (string), default: automatically generate salt &lt;br /&gt;
*** an empty string will automatically generate a salt with the ''cost'' provided&lt;br /&gt;
*** if a string is provided, the given salt is used (do not do this!)&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the hash as a string if hashing was successful, ''false'' otherwise. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Warning|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword)&lt;br /&gt;
			if (account) then -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50761</id>
		<title>PasswordHash</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50761"/>
		<updated>2017-04-22T12:45:08Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function creates a new password hash using a specified hashing algorithm.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to hash.&lt;br /&gt;
*'''algorithm:''' The algorithm to use:&lt;br /&gt;
** ''bcrypt'': use the bcrypt hashing algorithm&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''options:''' table with options for the hashing algorithm, as detailed below&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Options for each hashing algorithm===&lt;br /&gt;
* ''bcrypt'':&lt;br /&gt;
** ''cost'' (int), default: 10.  Visit [http://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt this link] to determine the number of rounds appropriate for your server.&lt;br /&gt;
** ''salt'' (string), default: automatically generate salt &lt;br /&gt;
*** an empty string will automatically generate a salt with the ''cost'' provided&lt;br /&gt;
*** if a string is provided, the given salt is used (do not do this!)&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the hash as a string if hashing was successful, ''false'' otherwise. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Note|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword)&lt;br /&gt;
			if (account) then -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50760</id>
		<title>PasswordHash</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50760"/>
		<updated>2017-04-22T12:44:50Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function creates a new password hash using a specified hashing algorithm.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to hash.&lt;br /&gt;
*'''algorithm:''' The algorithm to use:&lt;br /&gt;
** ''bcrypt'': use the bcrypt hashing algorithm&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''options:''' table with options for the hashing algorithm, as detailed below&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Options for each hashing algorithm===&lt;br /&gt;
* ''bcrypt'':&lt;br /&gt;
** ''cost'' (int), default: 10.  Visit [http://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt this link] to determine the number of rounds appropriate for your server.&lt;br /&gt;
** ''salt'' (string), default: automatically generate salt &lt;br /&gt;
*** an empty string will automatically generate a salt with the ''cost'' provided&lt;br /&gt;
*** if a string is provided, the given salt is used (do not do this!)&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the hash as a string if hashing was successful, ''false'' otherwise. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Deprecated|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword)&lt;br /&gt;
			if (account) then -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
	<entry>
		<id>https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50759</id>
		<title>PasswordHash</title>
		<link rel="alternate" type="text/html" href="https://wiki.multitheftauto.com/index.php?title=PasswordHash&amp;diff=50759"/>
		<updated>2017-04-22T12:40:44Z</updated>

		<summary type="html">&lt;p&gt;Kaasis: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
{{Shared function}}&lt;br /&gt;
{{Note box|Using '''passwordHash''' is the recommended way of storing passwords.}}&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11277|&lt;br /&gt;
This function creates a new password hash using a specified hashing algorithm.&lt;br /&gt;
}}&lt;br /&gt;
==Syntax== &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
===Required Arguments=== &lt;br /&gt;
*'''password:''' The password to hash.&lt;br /&gt;
*'''algorithm:''' The algorithm to use:&lt;br /&gt;
** ''bcrypt'': use the bcrypt hashing algorithm&lt;br /&gt;
===Optional Arguments===&lt;br /&gt;
*'''options:''' table with options for the hashing algorithm, as detailed below&lt;br /&gt;
{{New feature/item|3.0154|1.5.4|11281|&lt;br /&gt;
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.&lt;br /&gt;
}}&lt;br /&gt;
===Options for each hashing algorithm===&lt;br /&gt;
* ''bcrypt'':&lt;br /&gt;
** ''cost'' (int), default: 10.  Visit [http://security.stackexchange.com/questions/17207/recommended-of-rounds-for-bcrypt this link] to determine the number of rounds appropriate for your server.&lt;br /&gt;
** ''salt'' (string), default: automatically generate salt &lt;br /&gt;
*** an empty string will automatically generate a salt with the ''cost'' provided&lt;br /&gt;
*** if a string is provided, the given salt is used (do not do this!)&lt;br /&gt;
&lt;br /&gt;
===Returns===&lt;br /&gt;
Returns the hash as a string if hashing was successful, ''false'' otherwise. If a callback was provided, the aforementioned values are arguments to the callback, and this function will always return ''true''.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
{{Note|If you will be using &amp;quot;Example 1&amp;quot; then you will have to save account data &amp;quot;hash_password&amp;quot; after server restart, otherwise this script will no longer work.}}&lt;br /&gt;
This example makes use of passwordHash and passwordVerify in account creation and account login to boost up security.&lt;br /&gt;
&amp;lt;section name=&amp;quot;Example 1&amp;quot; class=&amp;quot;server&amp;quot; show=&amp;quot;true&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- lets add command handler that will handle the account creation&lt;br /&gt;
addCommandHandler(&amp;quot;accountCreate&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local hashedPassword = passwordHash(password,&amp;quot;bcrypt&amp;quot;) -- create new hash for password&lt;br /&gt;
		if (hashedPassword) then -- check if hash has been generated&lt;br /&gt;
			local account = addAccount(username,hashedPassword)&lt;br /&gt;
			if (account) then -- now lets add account with new hash what we got when we made it for password.&lt;br /&gt;
				setAccountData(account,&amp;quot;hash_password&amp;quot;,hashedPassword) -- store accounts password hash in order to verify it when it's needed.&lt;br /&gt;
				outputChatBox(&amp;quot;Account successfuly created! Now please login. Syntax &amp;lt;/accountLogin [username] [password]&amp;gt;&amp;quot;,source,20,160,20)&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Account already exists! Please try again with different username.&amp;quot;,source,20,160,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Securing your password failed! Please try again or contact an administrator.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&lt;br /&gt;
-- lets add command handler that will handle the account login&lt;br /&gt;
addCommandHandler(&amp;quot;accountLogin&amp;quot;,function(source,cmd,username,password)&lt;br /&gt;
	if (username and password) then&lt;br /&gt;
		local account = getAccount(username) -- get entered account&lt;br /&gt;
		if (account) then -- check if entered account exists&lt;br /&gt;
			local hashedPassword = getAccountData(account,&amp;quot;hash_password&amp;quot;) -- lets get hashed password&lt;br /&gt;
			if (passwordVerify(password,hashedPassword)) then -- check if hash and entered password matches&lt;br /&gt;
				if logIn(source,account,hashedPassword) then -- now lets login player into account&lt;br /&gt;
					outputChatBox(&amp;quot;Login successfull. Welcome, &amp;quot;..getAccountName(account)..&amp;quot;!&amp;quot;,source,20,160,20)&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				outputChatBox(&amp;quot;Password is incorrect!&amp;quot;,source,160,20,20)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			outputChatBox(&amp;quot;Account doesn't exist! Please try again with different account.&amp;quot;,source,160,20,20)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		outputChatBox(&amp;quot;Wrong parameters! Correct Syntax &amp;lt;/accountCreate [username] [password]&amp;gt;&amp;quot;,source,160,20,20)&lt;br /&gt;
	end&lt;br /&gt;
end);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/section&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
{{Utility functions}}&lt;/div&gt;</summary>
		<author><name>Kaasis</name></author>
	</entry>
</feed>