def hash_bcrypt(cls, password): if isinstance(password, unicode): password = password.encode('utf-8') hash_ = bcrypt.hashpw(password, bcrypt.gensalt()) return '$'.join(['bcrypt', hash_])