最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

flask框架實(shí)現(xiàn)修改密碼和免密登錄功能

 更新時(shí)間:2021年05月24日 15:29:25   作者:楊傳偉  
flask是python web開發(fā)的常用框架之一。本文將講述flask如何實(shí)現(xiàn)修改密碼和免密登錄功能

修改密碼功能

數(shù)據(jù)庫(kù)部分:

#重置密碼
def reset_pass(phone,password):
    conn,cursor=get_conn()
    sql="update userdata set userpass='"+password+"' where userphone='"+phone+"'"
    try:
        print("正在修改密碼...")
        resetflag=cursor.execute(sql)
        conn.commit()
        close_conn(conn,cursor)
        if(resetflag==1):
            print("修改成功")
            return 1
        else:
            print("修改失?。?)
            return 0
    except:
        print("系統(tǒng)錯(cuò)誤...修改密碼失??!")
        return 0

路由部分:

#用戶修改密碼
@app.route('/resetpass',methods=['GET', 'POST'])
def resetpass():
    userphone=request.values.get('userphone')
    resetpass=request.values.get('resetpass')
    print("路由獲得手機(jī)號(hào):"+userphone+"\n")
    print("路由獲得新密碼:" + resetpass + "\n")
    flag=sql.reset_pass(userphone,resetpass)
    if(flag==1):
        return jsonify({"data":1})
    else:
        return jsonify({"data":0})

html頁(yè)面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>樹懶電影---重置您的密碼</title>
    <style type="text/css">
        #resetform{
            margin-top: 350px;
            margin-left: 750px;
        }
    </style>
</head>
<body>
    <form method="post" id="resetform">
        <tr>
            <td><input type="text" id="userphone" value="" placeholder="輸入您的手機(jī)號(hào)碼"></td>
        </tr><br>
        <tr>
            <td><input type="password" id="resetpass1" value="" placeholder="輸入您的新密碼"></td>
        </tr><br>
        <tr>
            <td><input type="password" id="resetpass2" value="" placeholder="再次輸入您的新密碼"></td>
        </tr><br>
        <tr>
            <td><input type="reset" value="清空"></td>
            <td><input type="button" id="resetbtn" onclick="resetpass()" value="提交"></td>
        </tr>
    </form>
</body>
</html>
<script src="../static/js/jquery.min.js"></script>
<script type="text/javascript">
    function resetpass(){
        var userphone=document.getElementById("userphone").value
        var resetpass1=document.getElementById("resetpass1").value
        var resetpass2=document.getElementById("resetpass2").value
        var submit_flag=1
        //判空
        if((userphone.length==0)||(resetpass1.length==0)||(resetpass2.length==0)){
            submit_flag=0
            alert("請(qǐng)把信息填寫完整!")
        }
        //判斷密碼一致性
        if(resetpass2!=resetpass1){
            submit_flag=0
            alert("兩次填寫的密碼不一致")
            document.getElementById("resetpass1").focus();
        }
        //判斷手機(jī)號(hào)
        if(userphone.length!=11){
            submit_flag=0
            alert("手機(jī)號(hào)碼應(yīng)為11位!")
            document.getElementById("userphone").focus();
        }
        var regu =  /^1[3456789]\d{9}$/
        if(!(regu.test(userphone)) ){
            submit_flag=0
            alert("手機(jī)號(hào)碼格式有誤!")
            document.getElementById("userphone").focus();
        }
        //判斷密碼格式
        if(!((resetpass1.length>=6)&&resetpass1.length<=18))
        {
            submit_flag=0
            alert("密碼長(zhǎng)度應(yīng)該為6-16位!")
            document.getElementById("resetpass1").focus();
        }
            var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{6,18}');
            part_pass=resetpass1.split(" ")
        if((!(regex.test(resetpass1))) || part_pass.length!=1)
        {
            submit_flag=0
            alert("密碼為數(shù)字+英文字母 且不可以包含空格!")
            document.getElementById("resetpass1").focus();
        }

        //發(fā)起請(qǐng)求
            if(submit_flag==1)
        {
            $.ajax({
                url:"/resetpass",
                data:{userphone:userphone,resetpass:resetpass2},
                success: function (data) {
                    if (data.data==1)
                    {
                        alert("密碼修改成功!")
                        window.open("/",'_self')
                    }
                    else
                    {
                        alert("修改密碼失??!請(qǐng)重試")
                    }
                },
                error: function (xhr, type, errorThrown) {
                    // print("ajax請(qǐng)求失敗!")
                }
            })
        }
        // alert(submit_flag)
    }
</script>

免密登錄

html代碼:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="../static/css/login.css" rel="external nofollow" >
    <script src="../static/js/jquery-1.7.2.min.js"></script>
    <script src="../static/js/register.js"></script>
    <title>樹懶電影登錄</title>
    <script >
    </script>
</head>
<body>
    <div id="container">
        <div id="container-child">
            <div id="img-div"><img src="../static/img/shulan.png"></div>
            <div id="login-div">
                <div>
                    <p class="p-title">登錄您的樹懶電影</p>
                    <form id="login-form" method="post">
                        <div class="input-d">
                            <input class="input-text" type="text" name="userphone" id="userphone" placeholder="請(qǐng)輸入您的賬號(hào)">
                        </div>
                        <div class="input-d">
                            <input class="input-text" type="password" name="password" id="password" placeholder="請(qǐng)輸入您的密碼">
                        </div>
                        <div class="div-input">
                            <div>
                                <input type="checkbox" value=“1” class=“remeber” onclick="onClickHander(this)">
                                <label>記住密碼</label>
                            </div>
                        </div>
                        <button type="button" class="login-button" onclick="login_()">登 錄</button>
                        <div class="footer"> <a  rel="external nofollow" >注冊(cè)</a> | <a  rel="external nofollow" >忘記密碼</a></div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
    var cb=0
    function onClickHander(obj) {
        if(obj.checked==true){
            cb=1
            // alert(cb)
        }else{
            cb=0
            // alert(cb)
        }
    }
    function login_(){
        var userphone=document.getElementById("userphone").value
        var password=document.getElementById("password").value
        // alert(cb)
        $.ajax({
                url: "/web_login",
                data: {
                    userphone:userphone,password:password,cb:cb
                },
                success: function (data) {
                    //正常驗(yàn)證失敗彈窗
                    if (data.data == 0)
                        alert("賬號(hào)或密碼錯(cuò)誤!")
                    //驗(yàn)證成功,返回response
                    if (data.data != 0)
                        window.open("http://127.0.0.1:5000/show","_self")
                },
                error: function (xhr, type, errorThrown) {
                    print("登錄js,驗(yàn)證賬號(hào)密碼ajax請(qǐng)求失??!")
                }
        })
    }
</script>

Python路由

#免密登錄
@app.route('/web_login/',methods=['GET', 'POST'])
def web_login():
    userphone = request.values.get('userphone')
    password=request.values.get('password')
    cb=request.values.get('cb')
    print("是否記住密碼: "+cb)            #cb的返回值類型是 str 字符串
    # print(type(cb))
    print("登錄賬號(hào):"+userphone+"   "+"密碼:"+password)
    res=sql.web_login(userphone,password)
    if(res==True):
        session['userphone'] = userphone
        if(cb=="1"):
            print("開始存儲(chǔ)cookie登錄賬號(hào):" + userphone + "   " + "密碼:" + password)
            resp = make_response('儲(chǔ)存cookie')
            resp.set_cookie('cookphone', userphone, max_age=3600 * 24 * 15)
            resp.set_cookie('cookpass', password, max_age=3600 * 24 * 15)
            print("登錄成功且用戶選擇記住密碼,返回response")
            return resp                   #登錄成功且用戶選擇記住密碼,返回response
        else:
            print("登錄成功 返回 1 狀態(tài)碼")
            return jsonify({"data": 1})  # 登錄成功 返回 1 狀態(tài)碼
    else:
        print("登錄失敗   返回 0 狀態(tài)碼")
        return jsonify({"data":0})  #登錄失敗   返回 0 狀態(tài)碼

數(shù)據(jù)庫(kù)驗(yàn)證登錄

# 用戶(web)登錄驗(yàn)證
def web_login(userphone, password):
    cursor = None
    conn = None
    res=[]
    if(userphone==None or password==None):
        return False
    conn, cursor = get_conn()
    sql = "select userphone,userpass from userdata where '"+userphone+"'=userphone and '"+password+"'=userpass "
    res=query(sql)
    conn.commit()
    if(len(res)==0):
        print("登陸失?。╓EB)")
        close_conn(conn, cursor)
        return False
    else:
        close_conn(conn, cursor)
        print("登陸成功(WEB)")
        return True

以上就是flask框架實(shí)現(xiàn)修改密碼和免密登錄功能的詳細(xì)內(nèi)容,更多關(guān)于flask 修改密碼和免密登錄的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 巧用Python裝飾器 免去調(diào)用父類構(gòu)造函數(shù)的麻煩

    巧用Python裝飾器 免去調(diào)用父類構(gòu)造函數(shù)的麻煩

    巧用Python裝飾器 免去調(diào)用父類構(gòu)造函數(shù)的麻煩,需要的朋友可以參考下
    2012-05-05
  • 在flask中使用python-dotenv+flask-cli自定義命令(推薦)

    在flask中使用python-dotenv+flask-cli自定義命令(推薦)

    這篇文章主要介紹了在flask中使用python-dotenv+flask-cli自定義命令的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-01-01
  • Django框架獲取form表單數(shù)據(jù)方式總結(jié)

    Django框架獲取form表單數(shù)據(jù)方式總結(jié)

    這篇文章主要介紹了Django框架獲取form表單數(shù)據(jù)方式總結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-04-04
  • 用python寫一個(gè)windows下的定時(shí)關(guān)機(jī)腳本(推薦)

    用python寫一個(gè)windows下的定時(shí)關(guān)機(jī)腳本(推薦)

    由于本人經(jīng)常使用筆記本共享WiFi,但是又不想筆記本開機(jī)一夜,每次都是使用dos命令關(guān)機(jī),感覺好麻煩,然后小編想到用python寫一個(gè)定時(shí)關(guān)機(jī)的腳本,具體實(shí)例代碼請(qǐng)參考本文
    2017-03-03
  • Python+OpenCV之直方圖均衡化詳解

    Python+OpenCV之直方圖均衡化詳解

    直方圖均衡化是一種增強(qiáng)圖像對(duì)比度的方法,其主要思想是將一副圖像的直方圖分布變成近似均勻分布,從而增強(qiáng)圖像的對(duì)比度。本文將通過(guò)示例為大家講講直方圖均衡化的原理與實(shí)現(xiàn),感興趣的可以了解一下
    2022-09-09
  • 基于Python實(shí)現(xiàn)png轉(zhuǎn)webp的命令行工具

    基于Python實(shí)現(xiàn)png轉(zhuǎn)webp的命令行工具

    網(wǎng)頁(yè)上使用webp格式的圖片更加省網(wǎng)絡(luò)流量和存儲(chǔ)空間,但本地圖片一般是png格式的,所以本文就來(lái)為大家介紹一下如何使用Python實(shí)現(xiàn)png轉(zhuǎn)webp功能吧
    2025-02-02
  • Python學(xué)習(xí)之MRO方法搜索順序

    Python學(xué)習(xí)之MRO方法搜索順序

    這篇文章主要介紹了Python MRO方法搜索順序,文中代碼和圖片解釋的非常詳細(xì),可以很好的帶大家學(xué)習(xí)相關(guān)知識(shí)內(nèi)容,感興趣的小伙伴可以參考一下這篇文章
    2021-09-09
  • Python機(jī)器學(xué)習(xí)應(yīng)用之基于決策樹算法的分類預(yù)測(cè)篇

    Python機(jī)器學(xué)習(xí)應(yīng)用之基于決策樹算法的分類預(yù)測(cè)篇

    所謂決策樹,就是一個(gè)類似于流程圖的樹形結(jié)構(gòu),樹內(nèi)部的每一個(gè)節(jié)點(diǎn)代表的是對(duì)一個(gè)特征的測(cè)試,樹的分支代表該特征的每一個(gè)測(cè)試結(jié)果,而樹的每一個(gè)葉子節(jié)點(diǎn)代表一個(gè)類別。樹的最高層是就是根節(jié)點(diǎn)
    2022-01-01
  • python使用openpyxl庫(kù)處理Excel文件詳細(xì)教程

    python使用openpyxl庫(kù)處理Excel文件詳細(xì)教程

    這篇文章主要給大家介紹了關(guān)于python使用openpyxl庫(kù)處理Excel文件詳細(xì)教程的相關(guān)資料,openpyxl屬于第三方模塊,在python中用來(lái)處理excel文件,可以對(duì)excel進(jìn)行的操作有讀寫、修改、調(diào)整樣式及插入圖片等,需要的朋友可以參考下
    2023-11-11
  • 教你怎么用python刪除相似度高的圖片

    教你怎么用python刪除相似度高的圖片

    這篇文章主要介紹了教你怎么用python刪除相似度高的圖片,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-05-05

最新評(píng)論

崇仁县| 湘乡市| 冷水江市| 敖汉旗| 鄯善县| 乐业县| 安阳市| 垫江县| 尼木县| 汤阴县| 浑源县| 临颍县| 静乐县| 准格尔旗| 西华县| 城固县| 仁怀市| 班戈县| 自贡市| 蒙阴县| 辉县市| 华蓥市| 马龙县| 娄底市| 辰溪县| 曲阜市| 桂平市| 谷城县| 普洱| 大宁县| 湘阴县| 乐亭县| 灌阳县| 汝州市| 灵石县| 大埔县| 新郑市| 金门县| 靖西县| 顺平县| 花莲市|