By the way, your function createSalt() creates a new salt every time you call it! When you want to compare the original value and the database value, you hat to write the salt into a variable, then set it to your object, write to database, then retrieve from the database.