GetPasswordDifficulty: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "{{Useful Function}} <lowercasetitle/> __NOTOC__ This function checks the password difficulty ==Syntax== <syntaxhighlight lang="lua">int getPasswordDifficulty ( string passwo...")
 
 
(4 intermediate revisions by 2 users not shown)
Line 13: Line 13:


===Return===
===Return===
Returns a value from 1 to 5
Returns a value from 1


==Code==
==Code==
Line 20: Line 20:
     assert(type(password) == "string", "Bad argument @ getPasswordDifficulty [string expected, got " .. tostring(password) .. "]" )
     assert(type(password) == "string", "Bad argument @ getPasswordDifficulty [string expected, got " .. tostring(password) .. "]" )
     local strong = 0
     local strong = 0
     for i = 0, 9 do
     if string.find(password, "[0-9]") then
        if string.find(password, tostring(i)) then
        strong = strong + 1
            strong = strong + 1
        end
     end
     end
     if string.find(password, "%u") then
     if string.find(password, "%u") then

Latest revision as of 17:12, 7 April 2020

This function checks the password difficulty


Syntax

int getPasswordDifficulty ( string password )


Required arguments

  • password: The password whose difficulty you want to check

Return

Returns a value from 1

Code

function getPasswordDifficulty(password)
    assert(type(password) == "string", "Bad argument @ getPasswordDifficulty [string expected, got " .. tostring(password) .. "]" )
    local strong = 0
    if string.find(password, "[0-9]") then
        strong = strong + 1
    end
    if string.find(password, "%u") then
        strong = strong + 1
    end
    return strong
end

Example

Click to collapse [-]
Example

After using the command with a password, it returns its difficulty

function difficulty(commandName, password)
	if not password then
        return outputChatBox("Type password")
    end
    outputChatBox(getPasswordDifficulty(password))
end    
addCommandHandler("difficulty", difficulty)


Author: Liberty