Create a python login

txn

Joined
Oct 18, 2006
Messages
1
Reaction score
0
Hi folks,

I was trying to create a simple python login, but it seems does not work for me, here is the code i have done:


Code:
#!/soft/python-2.4-bin/python
print "Content-Type: text/HTML\n\n"

import cgi
#form = cgi.FieldStorage()

def check_login():
        form = cgi.FieldStorage()
        user = form.getfirst("username")
        password = form.getfirst("password")
        pwd = { 'user':    'password',
                'ta':      'ta',
        }
         
        if pwd.has_key(user):
                if password==pwd[user]:
                        print"You are now logged in"
                else:    
                        print "Invalid username or password\n"
                        form1()
        else:
                form1()

def form1():
   print """
        <html>
        <body>
        <FORM ACTION="assign5.cgi" METHOD="POST">
        <P><FONT SIZE="5" COLOR="#990000">Login</FONT><BR>
        
        <TABLE BORDER="0" WIDTH="271">
        <TR>
        <TD WIDTH="48%">
                <P ALIGN="RIGHT">Username:
        </TD>
        <TD WIDTH="1%">&nbsp;</TD>
        <TD WIDTH="51%"><INPUT TYPE="TEXT" NAME="username" SIZE="12"></TD>
        </TR>
        <TR>
                <TD WIDTH="48%">
                        <P ALIGN="RIGHT">Password:
                </TD>
                <TD WIDTH="1%">&nbsp;</TD>
<TD WIDTH="51%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="12"></TD>
                <INPUT TYPE = hidden NAME = "action\" VALUE = "display">
        </TR>
        <TR>
                <TD WIDTH="48%">&nbsp;</TD>
                <TD WIDTH="1%">&nbsp;</TD>
                <TD WIDTH="51%"><INPUT TYPE="SUBMIT" NAME="submit" VALUE="Login"><INPUT TYPE="RESET" NAME="Reset" VALUE="Clear"></TD>
        </TR>
</TABLE>
</FORM>"""

check_login()
print"</BODY></HTML>"

It works and shows the log in page. Now i can log in with the user name and pass correct, but if i put wrong pass or username then it doesn't say "Invalid username or password". I really want it say that "invalid username or password" with the log in form again but i have tried but it never work for me. Anyone has any idea? thanks first.
 
Joined
May 7, 2014
Messages
1
Reaction score
0
Solution

Hi, sorry if you got this answer a bit late but I found out the problem.


Instead of:

else: print "Invalid username or password\n"



try:

elif password != pwd[user]
print "Invalid..."






Hope this works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top