title: Writing MD5 (SALTED) password cracker
body: <p>I'm working on an assignment where I have to write a password cracker, to crack a password of which I have found the hashed value while compromising a system (.htpasswd) file on a web server.</p>
  
  <p>I've written the program and it works fine with simple and basic MD5 hashes, but the one I will be using is Salted MD5 hash.</p>
  
  <p>I've asked for assistance from my lecturer and he provided this:</p>
  
  <blockquote>
    <p>Import module from passlib.hash import apr_md5_crypt 
    use this function apr_md5_ crypt.encrypt(password, salt=salt) 
    where the password is the word from RockYou and salt is the value from the developer's hash value. This should help you out.</p>
  </blockquote>
  
  <p>I've added this in my program but it's still not picking the password from a wordlist that contains the password.</p>
  
  <p>The aim is to make my code work, not to find the password (I managed to get it in a previous stage using John The Ripper).</p>
  
  <pre><code> #!/usr/bin/env python
  
  #Importing algorithm
  import md5
  import hashlib
  import passlib.hash
  #Importing the algorithm for the hashed SALT
  from passlib.hash import apr_md5_crypt
  
  #The password is 1qa2ws3ed
  #The SALT value is Wv63/0xM
  
  counter = 1
  
  pass_in = raw_input("Please enter MD5 Hash: ")
  pwfile = raw_input("please enter the wordlist file name: ")
  
  #Opening the file to make sure the path is correct prior commencing to crack the password
  try:
     pwfile = open(pwfile, "r")
  except:
     print "\nFile Not found."
     quit()
  for password in pwfile:
     filemd5 = apr_md5_crypt.encrypt('1qa2ws3ed', salt='Wv63/0xM')
     md5.new(password.strip()).hexdigest()
     print "Trying password number %d: %s " % (counter, password.strip())
  
     counter += 1
  
     if pass_in == filemd5:
         print "\nMatch Found. \nPassword is: %s" % password
         break
  
  else: print "\nPassword Not Found."
  </code></pre>