Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 34 guests online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Programmingarrow Python Help
EH-Net
May 19, 2013, 02:15:25 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Python Help  (Read 3862 times)
0 Members and 1 Guest are viewing this topic.
tab
Newbie
*
Offline Offline

Posts: 2


View Profile
« on: August 17, 2009, 09:10:35 PM »

Hello, I'm new to this site. I have started studying programming as a hobby and I'm really getting into it, hopefully I can make a career out of it but if not I like it as a hobby.

Well, I started two days ago and I can't seem to be able to comprehend this little section.

This is the whole program but the part that is under the "---" is what I don't get.
I don't understand why there is a while loop on "logged" and why the "login" is phil, the password "McChicken" and why they are in while loop.

Sorry, for the long post I tried to make it as organized as best as I can.

tab-

Code:
while 1 == 1:
    nameguess=passwordguess=key=""
    while (nameguess != name) or (passwordguess != password):
        nameguess = raw_input('Name? ')
        passwordguess = raw_input('Password? ')
    print "Welcome,", name, ". Type lock to lock."
    while key != "lock":
        key = raw_input("")
-----------------------------
login = "john"
password = "tucker"
logged=2
 
while logged != 0:
    while login != "Phil":    
            login = raw_input("Login : ")
    while password != "McChicken":
            password = raw_input("Password: ")
    logged = 1
 
    print "Welcome!"
    print "To leave type lock "
 
    while logged == 1:
        leave = raw_input (">> ")
        if leave == "lock":
            logged = 0
print "Goodbye!!"




 
« Last Edit: August 18, 2009, 12:40:43 PM by tab » Logged
UNIX
Hero Member
*****
Offline Offline

Posts: 1234


View Profile
« Reply #1 on: August 18, 2009, 12:35:28 AM »

Hello tab and welcome to the forums.

When posting code snippets I would suggest to use the code tags [ code] insert code here [/ code] (without spaces) in order to keep the structure.

Are you sure that this is the whole program? Whats name and password in the first part? Just curious.


Code:
login = "john" (0)
password = "tucker" (0)
logged=2
 
while logged != 0: (1)
    while login != "Phil":   (2)
            login = raw_input("Login : ") (2)
    while password != "McChicken": (3)
            password = raw_input("Password: ") (3)
    logged = 1
 
    print "Welcome!" (4)
    print "To leave type lock " (5)
 
    while logged == 1: (6)
        leave = raw_input (">> ") (7)
        if leave == "lock": (8)
            logged = 0
print "Goodbye!!"

(1): Do the following as long as logged is different from 0 (which is at this state always the case because logged was declared with 2).
(2): As long as the entered username is different from Phil, ask again for the correct username. As soon as Phil was entered, it goes to (3)
(3): As long as the entered password is different from McChicken, ask again for the correct password. As soon as McChicken was entered, logged is set to 1 and the lines (4) and (5) are printed.

I am not sure why login and password at the beginning (0) are declared with different strings than later used, but I assume it is because to demonstrate that if you declare a variable at a later point with something different, the latest declaration/ comparison is valid.

E.g.
Code:
user = "tab"
password = "P()§"JND"

user = "tab2"
password = "ooooo"

print "user: " + user #displays user: tab2
print "pass: " + "password #displays pass: ooooo

(6): Do the following as long as logged is 1, which is at this point always the case, because it was before set to 1.
(7): Store all input done into leave (7). As soon as leave stores the string lock, logged is set to 0 which results in leaving the while loop (6) (because logged == 1 is not true anymore).

Hope you understand my explanations.
Logged
tab
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #2 on: August 18, 2009, 12:39:43 PM »

awsec, sorry for not putting the code tags in I already fixed it. As for the program It's from the python wiki tutorial (http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.0/Count_to_10). The whole program is stated under the "solution" part its the scond example of it.

But I did get what you mean though. But I can enter any username and password aside from what is written in the program and still manage to get in. That is the part that confuses me.


edit: Oh, I see where I did wrong its two different programs but I read it as one and yeah.. I'm sorry about this. Please disregard this topic and sorry for the newbie mistake  Sad

tab-
« Last Edit: August 18, 2009, 03:51:30 PM by tab » Logged
UNIX
Hero Member
*****
Offline Offline

Posts: 1234


View Profile
« Reply #3 on: August 19, 2009, 12:17:38 AM »

No need for apologizing. Glad you were able to proceed.

If you come across any other problems, feel free to ask.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.09 seconds with 22 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Advertisement

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.