新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
flask框架修改密碼和免密登錄具體方法
本篇文章重點(diǎn)為大家講解一下flask框架修改密碼和免密登錄具體方法,有需要的小伙伴可以參考一下。

目前創(chuàng)新互聯(lián)公司已為上千多家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、藍(lán)山網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
修改密碼功能
數(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è)面:
nbsp;html>
"UTF-8">
"viewport" content="width=device-width, initial-scale=1.0">
"X-UA-Compatible" content="ie=edge">
樹懶電影---重置您的密碼
"post" id=
"resetform">
type=
"text" id=
"userphone" value=
"" placeholder=
"輸入您的手機(jī)號(hào)碼">
type=
"password" id=
"resetpass1" value=
"" placeholder=
"輸入您的新密碼">
type=
"password" id=
"resetpass2" value=
"" placeholder=
"再次輸入您的新密碼">
type=
"reset" value=
"清空">
type=
"button" id=
"resetbtn" onclick=
"resetpass()" value=
"提交">
免密登錄
html代碼:
nbsp;html>
"UTF-8">
"viewport" content="width=device-width, initial-scale=1.0">
"X-UA-Compatible" content="ie=edge">
"stylesheet" href="../static/css/login.css" rel="external nofollow" >
樹懶電影登錄
"container">
"container-child">
"img-div">
"../static/img/shulan.png">
"login-div">
登錄您的樹懶電影
"login-form" method=
"post">
type=
"text" name=
"userphone" id=
"userphone" placeholder=
"請(qǐng)輸入您的賬號(hào)">
type=
"password" name=
"password" id=
"password" placeholder=
"請(qǐng)輸入您的密碼">
type=
"checkbox" value=“1” class=“remeber” onclick=
"onClickHander(this)">
記住密碼
type="button" onclick="login_()">登 錄
"http://127.0.0.1:5000/regis" rel=
"external nofollow" >注冊(cè) | "http://127.0.0.1:5000/reset" rel=
"external nofollow" >忘記密碼
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)容
文章標(biāo)題:flask框架修改密碼和免密登錄具體方法
網(wǎng)頁(yè)URL:http://m.fisionsoft.com.cn/article/cdgsohp.html


咨詢
建站咨詢
