<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 實例:用戶登錄 **創建用戶表userinfos** * 表結構如下 * id * uname * upwd * isdelete * 注意:需要對密碼進行加密 * 如果使用md5加密,則密碼包含32個字符 * 如果使用sha1加密,則密碼包含40個字符,推薦使用這種方式 ~~~ create table userinfos( id int primary key auto_increment, uname varchar(20), upwd char(40), isdelete bit default 0 ); ~~~ ## 加入測試數據 * 插入如下數據,用戶名為123,密碼為123,這是sha1加密后的值 ~~~ insert into userinfos values(0,'123','40bd001563085fc35165329ea1ff5c5ecbdbbeef',0); ~~~ ## 接收輸入并驗證 * 創建testLogin.py文件,引入hashlib模塊、MysqlHelper模塊 * 接收輸入 * 根據用戶名查詢,如果未查到則提示用戶名不存在 * 如果查到則匹配密碼是否相等,如果相等則提示登錄成功 * 如果不相等則提示密碼錯誤 ~~~ #encoding=utf-8 from MysqlHelper import MysqlHelper from hashlib import sha1 sname=raw_input("請輸入用戶名:") spwd=raw_input("請輸入密碼:") s1=sha1() s1.update(spwd) spwdSha1=s1.hexdigest() sql="select upwd from userinfos where uname=%s" params=[sname] sqlhelper=MysqlHelper('localhost',3306,'test1','root','mysql') userinfo=sqlhelper.get_one(sql,params) if userinfo==None: print '用戶名錯誤' elif userinfo[0]==spwdSha1: print '登錄成功' else: print '密碼錯誤' ~~~ ## python3代碼: ~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- ''' @Time : 5/15/18 1:43 AM @Author : haibo @File : Login.py ''' # 用自己封裝的MysqlHelper 模擬用戶登錄 from MysqlHelper import MysqlHelper import hashlib # 接收用戶輸入 name = input("請輸入用戶名:") pwd = input("請輸入密碼:") params = [name] # 對密碼加密 s1 = hashlib.sha1() s1.update(pwd.encode("utf-8")) spwd = s1.hexdigest() # 根據用戶名來查詢密碼 sql = "select upwd from userinfos where uname=%s" test = MysqlHelper("localhost", 3306, "python3", "root", "haibo") result = test.all(sql, params) if len(result) == 0: print("用戶名錯誤!") elif result[0][0] == spwd: print("登錄成功!") else: print("密碼錯誤!") ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看