Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 30th, 2012, 10:43 PM
OzzyTech OzzyTech is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 OzzyTech User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m
Reputation Power: 0
Python-Password

I have this code I'm working on. I'm trying to go back to the start of the program and keep on going back to the start of the program until the user enters the right password. Does anyone know what the python code would be in order for me to do this? the program does not have to quit, I want the program to keep on asking the user "Enter your password" until the user puts in "letmein". then I would continue to the rest of the program.

see code below, this is what I have so far.

#Password
password=raw_input("Enter your password:")

if password == "letmein":
print "hey your in"
else:
print"Denied"
password=raw_input("Enter your password:")
print"try again"
password=raw_input("Enter your password:")
print"Sorry, you got to go now"
raw_input ("Press enter to exit")
quit()

Reply With Quote
  #2  
Old December 31st, 2012, 08:14 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
Code:
import sys
for attempts in range(2):
    if 'some secret' == raw_input('password: '):
        break
    print('try again')
else:
    print('Pilot license revoked!')
    sys.exit(1)

print('<horse enter saloon>  Bartender: "Why the long face?"')
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 2nd, 2013, 03:03 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 483 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 51 m 26 sec
Reputation Power: 63
Contributing User b49P23TIvg is correct, you really should limit the number of attempts to something reasonable.

You can rewrite your code like this:
Code:
#Password

limit_attempts = 5
attempts = 1
while True:
    password = raw_input("Enter your password: ")
    if password == "letmein":
        print "Hey your in!"
        break
    else:
        print "Denied, try again!"
    if attempts >= limit_attempts:
        print"Sorry, you got to go now!"
        break        
    attempts += 1
    

raw_input("Press enter to exit")
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Python-Password

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap