简体   繁体   中英

creating a login page on python

I am just creating a login page using sqlite3 using it to save email id and its password so that I can check while login weather password is correct or not I did it till log in /signup it saves id password but while logging in I need to search whether the password is correct or not?

import sqlite3

conn = sqlite3.connect('test.db')

conn.execute('create table id(email varchar(40), password varchar(30));')
while True:

    form=input("\nsignup or login:  ")

    if form== 'signup' :

        email=input("input your email id:   ")

        if "@" and "." in email:

            password=input("create password:   ")

            conn.execute('insert into id values(?, ?);', (email, password))

            if len(password) >= 6:

                rpassword=input("renter password:  ")

                if password == rpassword:

                    print("sucessfully created")
                    break

                else:
                    print("Passwords didn't match")

            else:
                print("Your password is too short")


if form == 'login' :

    email2=input("your email   ")

    if "@" and "." in email2:

        password2=input("your password   ")

While it's a bad way to keep passwords in DB "as is", you can use this to check if user&password exists:

 conn.execute('SELECT EXISTS(SELECT 1 FROM id WHERE email=? AND password=?);', (email, password))

Also, calling table "id" is of no good as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM