Argon2 is a cryptographic hashing algorithm specifically used to hash passwords. It provides better protection against password cracking than other hashing algorithms like Bcrypt, Scrypt, and PBKDF2.
The Argon2 function takes in the password and outputs the hash of the specified length.
The argon2
function has three variants.
Argon2i
provides strong GPU resistance but has potential side-channel attacks.
Argon2d
Provides strong side-channel attack resistance.
Argoin2id
is the safest variant because it is a combination of the above two variants.
memory_cost
: the amount of memory in KB to be used.password
: password string to be hashed.salt_len
: length of random salt to be generated for each password.parallelism
: Number of parallel threads.time_cost
: Number of iterations over memory.hash_len
: Desired length of the output.type
: Argon2 variant to be used.import argon2argon2Hasher = argon2.PasswordHasher(time_cost=2,memory_cost=64,parallelism=1,hash_len=16,salt_len=16,type = argon2.low_level.Type(2))password = "@Educative123"hash = argon2Hasher.hash(password)print("Hashed password: ", hash)
In the code above:
PasswordHasher
class with custom parameters.argon2
function using the Type
function of another argon2
class named low_level
. Type IDs for argon2d
, argon2i
and argon2id
are 0, 1, and 2 respectively.hash
function with the password string.Note: Output hash changes every time you press the
Run
button. This is because randomly generated salt changes every time the hash function is called.
Free Resources