
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()

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()

Make bcrypt work with Unicode passwords
[Auth] Make bcrypt work with Unicode passwords

+ import bcrypt
+ from kitchen.text.converters import to_bytes
  
  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
+             to_bytes(value), salt=salt
          )
  
      def gen_salt(self):
          return bcrypt.gensalt()
  
Make bcrypt work with Unicode passwords
## Code Before:

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()

## Instruction:
Make bcrypt work with Unicode passwords
## Code After:
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()
