Borrowing code from set_password to support variable keyhash algo