Master - ghhoward/is210_lesson_06

Let's see what Jenkins does
Don't understand your comment. I was only testing for 'None' because of 
the Jenkins.
I did the direct testing of 'crack_it', and it looks like every user had 
a cracked password just like the answer in your review session on 
Wednesday. I don't understand any clear practical problem for the code 
not passing. Even your own answer seems functionally to be the same as 
mine. If you can explain what Jenkins tested for that I missed fine but, 
I don't understand what Jenkins had an issue with and most importantly 
how we could know it from the homework instructions. I am aware that I 
didn't get the list and tuple arrangement correct until the code below 
which still fails. However, I still have no idea what is wrong or most 
importantly how to repeat the correct answer in the future. As of this 
e-mail I don't see anyone in our class section who got the right answer 
and on Monday it looked like only one person got the answer on time.


On 10/09/2014 09:55 PM, Chad Heuschober wrote:
>
> In task_04.py:
>
> > +    >>> report(this_tuple)
> > +    Cracked Passwords
> > +    ----------------------------------------
> > +    root                satellites
> > +    Jill Lawrence       retinas
> > +    >>>
> > +    http://stackoverflow.com/questions/2990121/
> > +    how-do-i-loop-through-a-python-list-by-twos"""
> > +
> > +    print 'Cracked Passwords' + '\n' + ('-' * 40)
> > +    for usernam in this_tuple:
> > +        print "{0:<20}{1}".format(usernam[0], usernam[1])
> > +    return
> > +
> > +
> > +report(test_passwords(data.PASSWD))
>
> You need to test to see if |crack_it()| returns something (not none) 
> before adding the username and password to the list. As it is, you add 
> every answer response whether the password was cracked or not.
>
> —
> Reply to this email directly or view it on GitHub 
> <https://github.com/is210-2014-fall-02/is210_lesson_06/pull/2/files#r18685592>.
>
#!/usr/bin/env python -tt
# -*- coding: utf-8 -*-
""" task_04 Cracking Passwords
Specifications

Create a file named task_04.py

Import the data.py file.
Instantiate a variable named SALT and
assign it a value of 'monosodium-glutamate'.
Uses a function named test_passwords()
that accepts a list object parameter 'account'.
Print a user and password list

"""
import data

SALT = 'monosodium-glutamate'


def test_passwords(account):
     """ accepts a list object parameter 'account'
     using the known account format 'test_password'
     calls 'crack_it' finds passwords
     'test_passwords' build a tuple list and
     calls 'report' to user and password list

     Arguement:
     Takes list with data.PASSWD format

     Returns:
     Tuple list with user and password pairs.

     Example
     >>> import data
     >>> account = ['root:SKzYTp7qhvTMCti4RBYXmxuh9tM=:0:0:root:/home/root',
     'jlawrence:dK6XC5q3p0CiTu38lRZAQHZSYdU=:1:1:Jill 
Lawrence:/home/jlawrence']
     >>> print test_passwords(account)
     [('root', 'satellites'), ('Jill Lawrence', 'retinas')]
     >>>
     """
     user_id = []
     pass_hash = []
     hash_word = ''
     rep_tuple = []
     temptup = ()

     for user_id in account:
         pass_hash = user_id.split(':')
         hash_word = crack_it(pass_hash[1])
         temptup = (pass_hash[4], hash_word)
         rep_tuple.append(tuple(temptup))
     return rep_tuple


def crack_it(hash_w):
     """ Calls the data.crypt() function with each word and
     the SALT variable.
     Compare the result of the string returned by data.crypt() with
     that passed as the input parameter.

     Arguement:
     User hash string for password

     Return:
     Password as string
     the word in 'crack' if if a match is found.

     Example:
     from PASSWD = [
     'root:SKzYTp7qhvTMCti4RBYXmxuh9tM=:0:0:root:/home/root',
     >>> import data
     >>> crack_it('SKzYTp7qhvTMCti4RBYXmxuh9tM=')
      'satellites'
     >>>
     """
     for crack in data.WORDS:
         if hash_w == data.crypt(crack, SALT):
             return crack


def report(this_tuple):
     """ Report prints "this_tuple" list
     Prints a User name and password list

     Arguement:
     Takes a tuple or list in User, password pair order

     Returns:
     return empty or None

     Example:
     >>> this_tuple = [('root', 'satellites'), ('Jill Lawrence', 'retinas')]
     >>> report(this_tuple)
     Cracked Passwords
     ----------------------------------------
     root                satellites
     Jill Lawrence       retinas
     >>>
     http://stackoverflow.com/questions/2990121/
     how-do-i-loop-through-a-python-list-by-twos"""

     print 'Cracked Passwords' + '\n' + ('-' * 40)
     for usernam in this_tuple:
         print "{0:<20}{1}".format(usernam[0], usernam[1])
     return


report(test_passwords(data.PASSWD))