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:
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.
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%"> </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%"> </TD>
<TD WIDTH="51%"><INPUT TYPE="PASSWORD" NAME="password" SIZE="12"></TD>
<INPUT TYPE = hidden NAME = "action\" VALUE = "display">
</TR>
<TR>
<TD WIDTH="48%"> </TD>
<TD WIDTH="1%"> </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.