如何使用python语言实现用户登录系统

如何使用python语言实现用户登录系统,第1张

1、使用python3执行程序。按提示输入1或2,登录或退出程序

2、输入用户名后,如果用户名被锁定及无效用户名,程序会退出,请确保输入正确

3、输入用户名正确后,输入密码。用户名正确的情况下,密码连续输错三次,用户将被锁定,禁止登录系统

LZ,登陆功能有两个子功能:注册与登陆,,初学版如下:

dic = {}

a = raw_input("Please input your name...")

b = raw_input("Please input your passcode...")

dic[a] = b

print a,dic[a]

print '*******'

c = raw_input("Please input your name...")

if c == a:

    d = raw_input("Please input your passcode...")

    if d == dic[a]:

        print'Welcome back %s '%c,'and your passcode is %s',dic[a]

print 'End ...'

函数版如下:

#!/usr/bin/python

# -*- coding: utf-8 -*-

import os

dic = {}

def login(name,passcode):

dic['name'] = name

dic['passcode'] = passcode

def register():

while True:

n = raw_input("Please input your name...")

if n == dic['name']:

p = raw_input("Please input your passcode...")

if p == dic['passcode'] :

print'Welcome back %s '%dic['name'],'and your passcode is %s',dic['passcode']

print 'End ...'

break

else:

print'Your passcode is not correct,try again...'

continue

else:

print"You don't have an account,please register..."

break

a = raw_input("Please input your name...")

b = raw_input("Please input your passcode...")

login(a ,b)

print '**'

register()

字典的使用在面向对象的编程也是很灵活的,常用作可变长度参数传递;推荐一个网址:http://blog.csdn.net/moodytong/article/details/7647684

科科。。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11748110.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存