# coding=utf-8
import bcrypt
from kitchen.text.converters import to_bytes

from plugins.auth.crypto.algo_base import BaseAlgorithm

__author__ = 'Gareth Coles'


class BcryptAlgo(BaseAlgorithm):
    def check(self, hash, value, salt=None):
        return hash == self.hash(value, hash)

    def hash(self, value, salt):
        return bcrypt.hashpw(
            to_bytes(value), salt=salt
        )

    def gen_salt(self):
        return bcrypt.gensalt()

# coding=utf-8

from plugins.auth.crypto.algo_base import BaseAlgorithm

import bcrypt

__author__ = 'Gareth Coles'


class BcryptAlgo(BaseAlgorithm):
    def check(self, hash, value, salt=None):
        return hash == self.hash(value, hash)

    def hash(self, value, salt):
        return bcrypt.hashpw(
            value, salt=salt
        )

    def gen_salt(self):
        return bcrypt.gensalt()

--- 
+++ 
@@ -1,8 +1,8 @@
 # coding=utf-8
+import bcrypt
+from kitchen.text.converters import to_bytes
 
 from plugins.auth.crypto.algo_base import BaseAlgorithm
-
-import bcrypt
 
 __author__ = 'Gareth Coles'
 
@@ -13,7 +13,7 @@
 
     def hash(self, value, salt):
         return bcrypt.hashpw(
-            value, salt=salt
+            to_bytes(value), salt=salt
         )
 
     def gen_salt(self):
[Auth] Make bcrypt work with Unicode passwords
