Python Forum
Password Hacker Science Project
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Hacker Science Project
#3
Wow, that is too much effort Wall.
Before help - 444 lines of code Wall , and many of them redundant Dodgy  - you need Code Review first.
Let me start by - ever heard of lists, elif? You just don't add numbers to names - you make list!

Let's start
passwords = [""] * 6
Now, about global - the only time you need global is when you want to re-assign value within a function - and it is still a bad idea. Outer-scope variables are visible within enclosed functions as they are - without qualifier. Still, arguments are better

But still - you write a lot of redundant code - you first function - since only one condition will be true - all ifs, startig from second and excluding the last, should be elifs, and the last should be else


if which_password == 0:
   .....
elif which_password == 1:
   .....
But even that is still lousy! Why? You repeat yourself! And - as I was recently preached to on FB  Doh , there's a DRY approach (the priestess called it paradigm Huh ), Don't Repeat Yourself

So, instead of this monstrosity, you may write just that
 def check_userpass(password_index, password_guess, passwords):
    if password_index == 0:
        return password_guess == passwords[0]
    elif password_index <len(passwords):
        return MD5me(password_guess) == passwords[password_index]
    return False
Concise, readable and to the point.

I am done for now. Now your turn - start chopping away redundancies in your code
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
Password Hacker Science Project - by BenjC - Apr-17-2017, 04:49 PM
RE: Password Hacker Science Project - by volcano63 - Apr-17-2017, 07:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Password Guesser Project RedSkeleton007 17 11,159 Nov-29-2017, 07:24 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020