
import bcrypt
from docopt import docopt


def hash_password(password, cost_factor):
    return bcrypt.hashpw(bytes(password), bcrypt.gensalt(cost_factor)).decode('utf-8')

if __name__ == "__main__":
    arguments = docopt(__doc__)
    password = arguments['<password>']
    cost_factor = int(arguments['<cost-factor>'])
    print(hash_password(password, cost_factor))


import bcrypt
from docopt import docopt


def hash_password(password, cost_factor):
    return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(cost_factor)).decode('utf-8')

if __name__ == "__main__":
    arguments = docopt(__doc__)
    password = arguments['<password>']
    cost_factor = int(arguments['<cost-factor>'])
    print(hash_password(password, cost_factor))

Fix "string argument without an encoding" python3 error in bcrypt script
Fix "string argument without an encoding" python3 error in bcrypt script

generate-bcrypt-hashed-password raises an error on python3 since
`bytes` is called without an encoding argument. Replacing it with
`.encode` should fix the problem.

  
  import bcrypt
  from docopt import docopt
  
  
  def hash_password(password, cost_factor):
-     return bcrypt.hashpw(bytes(password), bcrypt.gensalt(cost_factor)).decode('utf-8')
+     return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(cost_factor)).decode('utf-8')
  
  if __name__ == "__main__":
      arguments = docopt(__doc__)
      password = arguments['<password>']
      cost_factor = int(arguments['<cost-factor>'])
      print(hash_password(password, cost_factor))
  
Fix "string argument without an encoding" python3 error in bcrypt script
## Code Before:

import bcrypt
from docopt import docopt


def hash_password(password, cost_factor):
    return bcrypt.hashpw(bytes(password), bcrypt.gensalt(cost_factor)).decode('utf-8')

if __name__ == "__main__":
    arguments = docopt(__doc__)
    password = arguments['<password>']
    cost_factor = int(arguments['<cost-factor>'])
    print(hash_password(password, cost_factor))

## Instruction:
Fix "string argument without an encoding" python3 error in bcrypt script
## Code After:

import bcrypt
from docopt import docopt


def hash_password(password, cost_factor):
    return bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(cost_factor)).decode('utf-8')

if __name__ == "__main__":
    arguments = docopt(__doc__)
    password = arguments['<password>']
    cost_factor = int(arguments['<cost-factor>'])
    print(hash_password(password, cost_factor))
