python-login

Login_1.py

#!/usr/bin/env python
#coding:utf-8
'''
author:yangying
filename:xi2.py
date:17-7-6 下午5:25
desc:

'''
user="root"
passwd="westos"
count=0
while count <4:
    if count==3:
        print ("再见")
        break
    else:
        user_input=raw_input("请输入用户名:")
        passwd_input=raw_input("请输入密码:")
        count += 1
        if user==user_input and passwd ==passwd_input:
            print ("登陆成功!")
            break
        else:
            print ("认证失败,请重新输入  你还有%d机会")%(3-count)

Login_2.py

#!/usr/bin/env python
#coding:utf-8
'''
author:yangying
filename:login_2.py
date:17-7-7 下午9:55
desc:

'''
users=["mengke",'songzhao']
passwd=['hello','hello']
def main():
    str='welcome to user login system'
    a="""
%s
(C)reate
(L)ogin
Enter choice:"""%str.center(10,'*')
    while True:
        choice=raw_input(a).lower()
        if choice == 'c':
            uname=raw_input("please input name:")
            if uname in users:
                print '用户已经存在,请直接登陆'
            else:
                upasswd=raw_input("please input password:")
                users.append(uname)
                passwd.append(upasswd)
                print '用户创建成功'
        elif choice == 'l':
            count=0
            while(count<3):
                uname = raw_input("please input name:")
                upasswd = raw_input("please input password:")
                b=len(users)
                for i in range (0,b):
                    if uname == users[i] and upasswd == passwd[i]:
                        print '用户登陆成功'
                        exit(0)
                    else:
                        count =count+1
                        print '用户名或密码错误,请重新输入,你还有%d次机会'%(3-count)
                        break
                    print '你已登陆了3次,请半小时后再登陆'
                else:
                    print '请输入c或l'
main()

 

 

 

posted @ 2017-07-07 22:49  yangying  阅读(1438)  评论(0编辑  收藏  举报