Reference/Native_modules/lu_hashing_MD5_and_SHA1

LoadModule("lu_hashing") adds two hash functions of the original Liberty Unleashed server. A hash turns any text into a fixed-length fingerprint; the same text always gives the same hash, and the text cannot be read back from it.

Functions

SHA1

SHA1(text)

The SHA-1 hash of a string as 40 lower-case hex digits: SHA1("abc") is a9993e364706816aba3e25717850c26c9cd0d89d. Throws when the argument is not a string (use SHA1(n.tostring())).

Returns: string

MD5

MD5(text)

The MD5 hash as 32 lower-case hex digits: MD5("abc") is 900150983cd24fb0d6963f7d28e17f72.

Returns: string

Storing passwords. Never store a password itself. Store a random salt per account and the hash of salt + password; to log in, hash the salt + the typed password again and compare.

LoadModule("lu_hashing");

function NewSalt()
{
    local s = "";
    for (local i = 0; i < 16; i++) s += format("%02x", rand() % 256);
    return s;
}

function Register(name, password)
{
    local salt = NewSalt();
    local hash = SHA1(salt + password);
    // store name, salt and hash (lu_sqlite2, lu_ini, ...) - not the password
}

function CheckPassword(salt, storedHash, typed)
{
    return SHA1(salt + typed) == storedHash;
}
NoteMD5 and SHA1 are fast, which also makes them easy to brute force: a salt per account and a minimum password length are the least you should do. This module comes from the original Liberty Unleashed server; there is no source code for it.
Categories: Native modules