Secure password hashing in R with bcrypt
June 19, 2015
The new package bcrypt provides an R interface to the OpenBSD ‘blowfish’ password hashing algorithm described in A Future-Adaptable Password Scheme by Niels Provos. The implementation is derived from the py-bcrypt module for Python which is a wrapper for the OpenBSD implementation.
Bcrypt is used for secure password hashing. The main difference with regular digest algorithms such as md5 / sha256 is that the bcrypt algorithm is specifically designed to be cpu intensive in order to protect against brute force attacks. This means that hasing with bcrypt is terribly slow, which is a feature. The complexity of the algorithm is configurable via the
The API from the R package is exactly the same as the one from python: the
hashpw function calculates a hash from a password using a random salt. Validating the hash is done by reshashing the password using the hash as a salt.
gensalt function generates a salt for use with
hashpw and specifies the complexity of the algorithm via the
log_rounds parameter. The first few characters in the salt string hold the bcrypt version and value for log_rounds. The remainder stores 16 bytes of base64 encoded randomness for seeding the hashing algorithm.