Python Forum
Writing incorrect passwords to a file till its correct
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing incorrect passwords to a file till its correct
#1
# Now, create a Python file called forgetful.py . Imagine your friend was very forgetful and always seemed to enter his email password incorrectly. You want to write a Python program that takes all his incorrect password entries, stores it in a list, then records 
# all his incorrect password entries in a text file called wrongpasswords.txt. 

# Example: your friends password is 'rusty'. But he enters 'rusty123', 'Rusty', 'rustless' before finally remembering his password is 'rusty' and entering it correctly.

# In this situation wrongpasswords.txt should read this exactly:
# Incorrect password 1: rusty123
# Incorrect password 2: Rusty
# Incorrect password 3: rustless
# Correct password entered on 4th entry.

# The program should ask the user for input by saying 'Please enter your password'. The correct password will always be 'rusty' but the user can of course enter any String.
# Good luck!

i am suppose to write entered passwords to the file till the "Correct" one is inputted which is "rusty" but i cant seem to get it right and ive spent over a couple of hours trying.. please help this is what i have coded:
enteredPass = raw_input("Enter your password: ")
incorrectPass= file("wrongpasswords.txt","w")                      
counter = 0



for i in range(0, counter+1):
    
    if enteredPass != "rusty":
        counter = counter +1
        incorrectPassO = open("wrongpasswords.txt","w")
        incorrectPassO.write("Incorrect password" +str(counter)+": " + enteredPass + "\n")
        incorrectPassO.close()
        enteredPass = raw_input("Enter your password: ")
        
        
    else:
        incorrectPassO = open("wrongpasswords.txt","w")

        incorrectPassO.write("Correct password entered on the " + str(counter)+"th entry")
        incorrectPassO.close()
Reply


Messages In This Thread
Writing incorrect passwords to a file till its correct - by garth - Feb-10-2017, 07:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting an incorrect average, and not sure why? What's wrong with my code? shirleylam852 8 4,804 Nov-20-2020, 05:32 AM
Last Post: deanhystad
  Hashing Passwords (HELP) MianDoesCoding 4 2,250 May-26-2020, 03:11 PM
Last Post: buran
  How to make the function to prompt the user repeatedly till he enters a no sbabu 3 2,466 Mar-26-2020, 10:04 PM
Last Post: Blackdog31
  Multiple Passwords NotPythonQueen 17 6,928 Sep-22-2019, 06:08 PM
Last Post: gbs
  Correct errors in text file. pawlo392 2 2,275 Apr-17-2019, 07:55 PM
Last Post: pawlo392
  reading text file and writing to an output file precedded by line numbers kannan 7 10,532 Dec-11-2018, 02:19 PM
Last Post: ichabod801
  Return giving incorrect value Calingaladha 5 3,429 Oct-24-2018, 09:53 PM
Last Post: LeSchakal
  Writing to a .py file J0k3r 3 3,425 Apr-18-2018, 07:01 PM
Last Post: woooee
  Incorrect code janek30 11 8,542 May-09-2017, 10:06 AM
Last Post: janek30

Forum Jump:

User Panel Messages

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