Skip to content

ryancdotorg/mariadb-bcrypt-udf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a set user-defined functions for MariaDB.

It should work with MySQL with trivial modifications (change the include directory in the Makefile), but I have not tested this.

I'm using Openwall's bcrypt implementation, and some of the interfacing code was cribbed from Ricardo Garcia's bcrypt wrapper library.

Two functions are defined:

BCRYPT_HASH(password, work_factor)

Returns a bcrypt $2b$ hash for the provided password with a random salt and the given work factor. If work_factor is NULL, a sensible default (currently 12) will be used. The work_factor is clamped to be between 4 and 16 inclusive - if you want to allow smaller or larger work factors, change WORKFACTOR_MIN and/or WORKFACTOR_MAX in bcrypt.c. Returns NULL on error.

Note that passwords containing null bytes are not supported and will cause an error.

BCRYPT_CHECK(password, hash)

Returns 1 if the supplied password matches the hash, 0 if not. Returns NULL on error.

Note that passwords containing null bytes are not supported and will cause an error.

Installing

Only tested on Debian Jessie with MariaDB 10.0. Please do not file issues about this not compiling on other platforms without including a patch.

sudo apt-get install libmariadb-client-lgpl-dev build-essential
make clean all
sudo cp bcrypt.so /usr/lib/mysql/plugin/
mysql -e "drop function if exists bcrypt_hash;  create function bcrypt_hash  returns string  soname 'bcrypt.so';"
mysql -e "drop function if exists bcrypt_check; create function bcrypt_check returns integer soname 'bcrypt.so';"

WARNING

Since bcrypt deliberately uses a lot of CPU time, these functions could be used to DoS your database server. Use with caution. The work factor supplied by the hash is NOT currently limited and may take minutes to run with large values.

About

bcrypt user-defined functions for MariaDB/MySQL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published