Hello everyone ! Im currently developing a login system with Python and using MySQLDB. Im currently stuck at letting the program access the database and check if the username and password entered by the user matches or no. I googled, youtubed and still cant find any working result.
Current Python Code:
MySQL Script:
Current Python Code:
Code:
import MySQLdb
neworold=raw_input("Welcome to the Logon System! Had you got an account? (Y/N): ")
while neworold=="N" or neworold=="n":
print"Please register an account!"
username=raw_input("Username: ")
password=raw_input("Password: ")
name=raw_input("Real Name: ")
email=raw_input("Email: ")
hpnum=raw_input("HP No.: ")
# Open database connection
db = MySQLdb.connect("localhost","root","","logon" )
cursor = db.cursor()
sql = "INSERT INTO accounts (username, password, name, email, hpnum) \
VALUES ('%s', '%s', '%s', '%s', '%s' )" % \
(username, password, name, email, hpnum)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
print"Account Registered!"
neworold="Y"
print"Please login into your account!"
while neworold=="Y" or neworold=="y":
username=raw_input("Username: ")
password=raw_input("Password: ")
db = MySQLdb.connect("localhost","root","","logon" )
cursor = db.cursor()
if cursor.execute("SELECT * FROM `accounts` where `username`= ' " + username + " ' AND `password` =' " + password + " ' "):
print "Welcome back! "
else:
print"Incorrect username or Password"
MySQL Script:
Code:
/*!40101 SET @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
CREATE DATABASE IF NOT EXISTS logon;
USE logon;
--
-- Definition of table `accounts`
--
DROP TABLE IF EXISTS `accounts`;
CREATE TABLE `accounts` (
`userid` int(11) NOT NULL auto_increment,
`username` varchar(13) NOT NULL default '',
`password` varchar(128) NOT NULL default '',
`name` tinytext,
`email` tinytext,
`hpnum` int(11),
PRIMARY KEY (`userid`),
UNIQUE KEY `username` (`username`),
KEY `userid` (`userid`)
) ENGINE=InnoDB AUTO_INCREMENT=526 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;
/*!40101 SET SQL_MODE @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_COLLATION_CONNECTION */;
/*!40101 SET CHARACTER_SET_CLIENT @[I][B][URL="https://forum.ragezone.com/members/1333464006.html"]old[/URL][/B][/I]_CHARACTER_SET_CLIENT */;
Last edited: