title: md5 encrypting passwords from str(input)
body: <p>im trying to hash a password from a file and then match it with the password given by the user. it's not ment to be super safe just safe enought so that the password isn't plain text in the file.
  I get the error </p>
  
  <pre><code>TypeError: Unicode-objects must be encoded before hashing
  </code></pre>
  
  <p>it works if i type hashpass = hashlib.md5(b'p').hexdigest()
  but then it only encrypts "p"</p>
  
  <p>How do i get it to encrypt my string inputs?</p>
  
  <p>PROGRAM</p>
  
  <pre><code>import hashlib
  
  status = ""
  
  def passhash():    
      code = open("password.txt", "r")
      password = code.readline()                
      global encrypt
      encrypt = hashlib.md5(password).hexdigest()
  
  def checkPassword():
      for key in range(3):        
          p = input("Enter the password &gt;&gt;")      
          hashpass = hashlib.md5(p).hexdigest()
  
          if hashpass == encrypt:            
              print("password correct!")
              status = "q"
              return status
          else:
              print ('wrong password, try again')
      print ('you have failed')
  
  def Main():
      status = input("p for program, q to quit: ")
      if status == "p":
          passhash()
          checkPassword()
      elif status == "q":
          print("Byebye")
          status = "q"
          return status
  
  while status != "q":            
      status = Main()}
  </code></pre>