python實現簡單登陸流程

2022-06-16 07:30:11 字數 2126 閱讀 5922

登陸流程圖:

**實現:

#-*- coding=utf-8 -*-

import os,sys,getpass

'''user.txt 格式

賬號 密碼 是否鎖定 錯誤次數

jack 123 unlock 0

tom 123 unlock 0

lily 123 unlock 0

hanmeimei 123 unlock 0

lucy 123 unlock 0

'''# 定義寫入檔案的函式

def wirte_to_user_file(users,user_file_path):

user_file = file(user_file_path,'w+')

for k,v in users.items():

line =

line.extend(v)

user_file.write(' '.join(line)+'\n')

user_file.close()

# 判斷使用者檔案是否存在,不存在直接退出

user_file_path = 'users.txt'

if os.path.exists(user_file_path):

user_file = file(user_file_path,'r')

else:

print 'user file is not exists'

sys.exit(1)

# 遍歷使用者檔案,將使用者包裝成字典

users_dic = {}

for user_line in user_file:

user = user_line.strip().split()

users_dic[user[0]] = user[1:]

''''''

while true:

# 輸入賬號

input_name = raw_input('please input your username,input "quit" or "q" will be exit : ').strip()

# 判斷是否為退出

if input_name == 'quit' or input_name == 'q':

sys.exit(0)

# 輸入密碼

password = getpass.getpass('please input your password:').strip()

# 判斷賬號是否存在、是否鎖定

if input_name not in users_dic:

print 'username or password is not right'

break

if users_dic[input_name][1] == 'lock':

print 'user has been locked'

break

# 判斷密碼是否正確,正確,登陸成功

if str(password) == users_dic[input_name][0]:

print 'login success,welcome to study system'

sys.exit(0)

else:

# 如果密碼錯誤則修改密碼錯誤次數

users_dic[input_name][2] = str(int(users_dic[input_name][2])+1)

# 密碼錯誤次數大於3的時候則鎖定,並修改狀態

if int(users_dic[input_name][2]) >= 3:

print 'password input wrong has 3 times,user will be locked,please connect administrator'

users_dic[input_name][1] = 'lock'

wirte_to_user_file(users_dic,user_file_path)

break

wirte_to_user_file(users_dic,user_file_path)

超簡單的springMVC實現登陸流程

springmvc是 spring 框架裡面的乙個模組 用法和 springioc 不一樣,但是同時用也可以,springmvc本身的 jar包 spring web 4.3.10.release spring webmvc 4.3.10.release 加上springioc和 aop的包總共是這...

遊戲登陸流程

今天主要講遊戲的登陸流程,由於我們的後台架構是前端接入層 後端業務程序的架構模式,因此,任何網路連線請求的資料,都要經過前端接入。首先要說明,目前大多數遊戲都是 賬號 角色的模式。ok 登陸兩種模式1,已在該服建立過賬號,建立過角色的玩家 2.在該服沒有建立過,賬號資料庫是沒有資料 我們首先說一下我...

python 實現介面 python實現登陸介面

資料夾結構 now we must the first to design the db.py import pymysql conn pymysql.connect localhost root test cur conn.cursor def insert username,password s...