User Registration

Member Login System

Registration window will take three inputs name, userid and password from user. After validation the data will be stored in MySQL database table. You can use the SQL dump available at login system page.

Login registration main Window

Validating inputs

The registration window takes three inputs from the user. There are input validations done before adding the entered data to MySQL database.
  1. Name must be minimum 4 char length.
  2. Password must be minimum 6 char length.
  3. Userid should not be less than 5 and more than 12 char length
  4. Userid should only contain alphanumeric chars.
  5. Userid must not be already in use ( should be unique )

#### End of main window #### 
def my_registration():
    my_w_child=Toplevel(my_w) # Child window 
    my_w_child.geometry("300x200")  # Size of the window 
    my_w_child.title("www.plus2net.com")

    my_str1 = tk.StringVar()
    l1 = tk.Label(my_w_child,  textvariable=my_str1 )
    l1.grid(row=1,column=2,columnspan=2,sticky='E') 
    my_str1.set("-Registration--")
    
    my_str = tk.StringVar()
    l1 = tk.Label(my_w_child,  textvariable=my_str,width=15 )
    l1.grid(row=2,column=2) 
    my_str.set("Name")
    name1 = tk.Entry(my_w_child, width=15) # added one Entry box
    name1.grid(row=2,column=3)
    
    my_str2 = tk.StringVar()
    l2 = tk.Label(my_w_child, textvariable=my_str2 )
    l2.grid(row=3,column=2) 
    my_str2.set("Userid")
    userid2 = tk.Entry(my_w_child, width=15) # added one Entry box
    userid2.grid(row=3,column=3)
    
    my_str3 = tk.StringVar()
    l3 = tk.Label(my_w_child, textvariable=my_str3 )
    l3.grid(row=4,column=2) 
    my_str3.set("Password")
    pw3 = tk.Entry(my_w_child, width=15,show='*') # added one Entry box
    pw3.grid(row=4,column=3)
    
    b4 = tk.Button(my_w_child, text='Register', command=lambda:add_data())
    b4.grid(row=5,column=3)
    
    my_msg = tk.StringVar()
    l5 = tk.Label(my_w_child,  textvariable=my_msg)
    l5.grid(row=6,column=1,columnspan=4,sticky='W') 
    my_msg.set("Add data")
    ## layout is over , now adding data to table 

    def add_data():
        flag_validation=True # set the flag 
        my_name=name1.get()     # read name
        userid=userid2.get()    # read userid
        pw=pw3.get()            # read password
        msg = ""
        # validation of entered data
        if(len(my_name) <=3): # length of name minimum 4 char
            flag_validation=False 
            msg = msg + "Name minimum 4 char \n "
        if(len(pw) <6): # length of password minimum 6 char
            flag_validation=False 
            msg = msg + "password must be minimum 6 char \n "    
        if(len(userid) <5 or len(userid)>12 or not userid.isalnum()): # userid between 5 and 12
            flag_validation=False 
            msg = msg + "Userid should not be less than 5 \n and more than 12 \n Special chars not allowed "
        else:
            #my_data=(userid,)
            #print(type(my_data))
            #my_query="SELECT * FROM mem WHERE userid='" + userid + "'" 
            my_query="SELECT * FROM mem WHERE userid=%s" #? for sqlite 
            r_set=my_conn.execute(my_query,userid)
            no=len(r_set.fetchall())
            if(no>0):
                flag_validation=False 
                msg = msg + "userid exists select different one "
        if(flag_validation):
            try:
                my_msg.set("Adding data...")
                my_data1=(my_name,userid,pw)
                my_query="INSERT INTO mem(name,userid,password) values(%s,%s,%s)"
                curs=my_conn.execute(my_query,my_data1)
                #my_conn.commit()
                #x=my_conn.execute('''select last_insert_rowid()''')
                #id=x.fetchone()
                msg="Record added, ID : "+ str(curs.lastrowid)
                name1.delete(0,END)   # delete the entered text
                userid2.delete(0,END) # delete the entered text
                pw3.delete(0,END)     # delete the entered text
            except Exception as e: 
                print(e)

        if(flag_validation):
            l5.config(fg='green')
        else:
            l5.config(fg='red')
        my_msg.set(msg)
        msg=''
        my_w_child.after(3000, lambda: my_msg.set(''))    
#### End of Registration process ####
Main Login script Member Login Member Listing

Download login-system.ipynb file ( zip )
Displaying records from student table
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer