PasswordHash: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (add salt rounds guidance link)
m (add callback functionality)
Line 7: Line 7:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string passwordHash ( string password, string algorithm [, table options = {} ] )   
string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])   
</syntaxhighlight>  
</syntaxhighlight>  


Line 16: Line 16:
===Optional Arguments===
===Optional Arguments===
*'''options:''' table with options for the hashing algorithm, as detailed below
*'''options:''' table with options for the hashing algorithm, as detailed below
 
{{New feature/item|3.0154|1.5.4|11281|
*'''callback:''' providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.
}}
===Options for each hashing algorithm===
===Options for each hashing algorithm===
* ''bcrypt'':
* ''bcrypt'':
Line 25: Line 27:


===Returns===
===Returns===
Returns the hash as a string if hashing was successful, ''false'' otherwise.
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''.


==Example==  
==Example==  

Revision as of 18:47, 19 April 2017

This template is no longer in use as it results in poor readability. This function creates a new password hash using a specified hashing algorithm.

Syntax

string passwordHash ( string password, string algorithm [, table options = {} ][, function callback ])  

Required Arguments

  • password: The password to hash.
  • algorithm: The algorithm to use:
    • bcrypt: use the bcrypt hashing algorithm

Optional Arguments

  • options: table with options for the hashing algorithm, as detailed below
  • callback: providing a callback will run this function asynchronously, the arguments to the callback are the same as the returned values below.

Options for each hashing algorithm

  • bcrypt:
    • cost (int), default: 10. Visit this link to determine the number of rounds appropriate for your server.
    • salt (string), default: automatically generate salt
      • an empty string will automatically generate a salt with the cost provided
      • if a string is provided, the given salt is used (do not do this!)

Returns

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.

Example

Accessories-text-editor.png Script Example Missing Function PasswordHash needs a script example, help out by writing one.

Before submitting check out Editing Guidelines Script Examples.
-- TODO


See Also