In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Write a simple login verification process
First create the directory structure
Model is related to the operation of database tables. Admin.py corresponds to the admin table under database member in the mysql database.
Utility is about manipulating databases.
Conf.py files are configuration strings
Index.py is the front entrance to the program.
First, the code in index.py:
#! / usr/bin/env python#coding:utf-8from model.admin import Admindef main (): user = raw_input ('inpute your username:') pawd = raw_input (' inpute your password:') admin = Admin () result = admin.CheckValiData (user, pawd) if not result: print "username or password not right!" Else: print "% s login success"% userif _ _ name__=='_ _ main__': main ()
Find the user name and password through the Admin class:
The code in the admin.py file:
#! / usr/bin/env python#coding:utf-8from utility.SqlHelper import MySqlHelperclass Admin (object): def _ _ init__ (self): self.__helper= MySqlHelper () def CheckValiData (self,username,password): sql= "select * from admin where name=%s and password=%s" parmars= (username,password,) return self.__helper.Get_One (sql, parmars)
The Admin class calls the MySqlHelper class to operate the database
The code in the SqlHelper.py file:
#! / usr/bin/env python#coding:utf-8import MySQLdbimport confclass MySqlHelper (object): def _ _ init__ (self): self.__dict=conf.db_dict def Get_One (self,sql,parmars): conn = MySQLdb.connect (* * self.__dict) cur= conn.cursor () recount = cur.execute (sql Parmars) data = cur.fetchone () cur.close () conn.close () return data
The code in the conf.py file:
# / usr/bin/env python#coding:utf-8db_dict = dict (host='127.0.0.1',user='root',passwd='redhat',db='member')
The contents of the admin table in mysql database are as follows:
Mysql > select * from admin;+----+ | id | name | password | +-- + | 1 | tom | 123 | 2 | jack | 1234 | +-+ 2 rows in set (0.00 sec) mysql >
The output result of executing python index.py is as follows:
[root@web Mysqlhelper] # python index.pyinpute your username:tominpute your password:123tom login success [root@web Mysqlhelper] # python index.pyinpute your username:jackinpute your password:12334username or password not right! [root@web Mysqlhelper] #
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.