寫了一個(gè)簡單的登錄驗(yàn)證過程
首先創(chuàng)建目錄結(jié)構(gòu)
model 是操作數(shù)據(jù)庫表相關(guān)的 admin.py是對應(yīng)于mysql 數(shù)據(jù)庫中的數(shù)據(jù)庫member下的admin表
utility是關(guān)于操作數(shù)據(jù)庫相關(guān)的
conf.py 文件是一些配置字符串
index.py 是程序前端入口
首先index.py中的代碼:
#!/usr/bin/env python #coding:utf-8 from model.admin import Admin def 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" % user if __name__== '__main__': main()通過Admin類查找用戶名和密碼:
admin.py文件中的代碼:
#!/usr/bin/env python #coding:utf-8 from utility.SqlHelper import MySqlHelper class 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)Admin類調(diào)用MySqlHelper類來操作數(shù)據(jù)庫
SqlHelper.py文件中的代碼:
#!/usr/bin/env python #coding:utf-8 import MySQLdb import conf class 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 dataconf.py文件中的代碼:
#!/usr/bin/env python #coding:utf-8 db_dict = dict(host='127.0.0.1',user='root',passwd='redhat',db='member')mysql數(shù)據(jù)庫中的admin表的內(nèi)容如下:
mysql> select * from admin; +----+------+----------+ | id | name | password | +----+------+----------+ | 1 | tom | 123 | | 2 | jack | 1234 | +----+------+----------+ 2 rows in set (0.00 sec) mysql>執(zhí)行python index.py輸出結(jié)果如下:
[root@web Mysqlhelper]# python index.py inpute your username:tom inpute your password:123 tom login success [root@web Mysqlhelper]# python index.py inpute your username:jack inpute your password:12334 username or password not right! [root@web Mysqlhelper]#另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
標(biāo)題名稱:簡單的登入驗(yàn)證-創(chuàng)新互聯(lián)
瀏覽地址:http://vcdvsql.cn/article20/djjhco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、手機(jī)網(wǎng)站建設(shè)、建站公司、關(guān)鍵詞優(yōu)化、營銷型網(wǎng)站建設(shè)、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容