title: Python Enter Password And Compare to Shadowed Password Database
body: <p>Good Day.</p>
  
  <p>Im trying to write a python script that will take a captured password then compare it
  to the system shadowed password.</p>
  
  <p>Im using Ubuntu 12.10 for this test. and running the script as sudo.</p>
  
  <pre><code>def login(user, password):
      "Check if user would be able to login using password"
      try:
          pw1 = spwd.getspnam(user)[1]
          allus = spwd.getspall()
          print pw1
          # pw2 = crypt.crypt(password, pw1[:2])
          pw2 = crypt.crypt(password, '\$6\$SALTsalt\$')
          print pw2
          return pw1 == pw2
      except KeyError:
          return 0 # no such user
  </code></pre>
  
  <p>Now the above  returns </p>
  
  <p>2 diferent passwords but i do get the one from the shadowed.</p>
  
  <p>So my question is how do i encrypt the supplied password so i can compare it to the 
  one retreived. Any Help would be awsome</p>
  
  <p>Edit addon</p>
  
  <pre><code>def login(user, password):
   "Check if user would be able to login using password"
   try:
      pw1 = spwd.getspnam(user)[1]
      allus = spwd.getspall()
    #        print allus
      print pw1
    #        pw2 = crypt.crypt(password, pw1[:2])
    # pw2 = crypt.crypt(password, '\$6\$SALTsalt\$')
  pw2 =hashlib.new()
  pw2.update(password)
  pw2.digest()
  
      print pw2
      return pw1 == pw2
   except KeyError:
      return 0 # no such user
  </code></pre>
  
  <p>That also did not work
  How does one impliment the haslib to get the hash to match system password</p>