Python Forum
Password Hacker Science Project
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Hacker Science Project
#1
Hello,

I need some help with my science fair project. If you want to look at the sit I got my idea from just google "How easily can your password be hacked science fair".   I am not sure that I have the code correct or even that I attached the password txt correctly. Here is my code though:

When I run the code it doesnt even try to use method 3 or 4 so it only tries to guess a string of numbers but no letters.

Moderator sparkz_alot:
Added spoiler tags
Reply
#2
This looks as if it was just copied from the web site.  It also seems the site has it's own forum regarding this particular lesson.  So what leads you to believe it's not using tests 3 and 4?  Did you modify the code? Did you modify the text file? Are you receiving any errors?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Password Guesser Project RedSkeleton007 17 11,026 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