首页 > 代码库 > 用户登陆python脚本

用户登陆python脚本

用户登陆,用已知的user和passwd登陆,先判断用户是否合法,然后输入密码,判断密码是否正确,如果输入三次错误密码,则自动跳出。否则输出用户error



#!/usr/bin/python
import getpass
#coding=utf-8
user = "root"
passwd = "westos"
username = raw_input("please input the username:")
if username == user:
    password = getpass.getpass("please input the password:")
    if password == passwd:
        print "login success"
    else:
        password = getpass.getpass("please input the password again:")
        if password == passwd:
                    print "login success"
         else:
                password = getpass.getpass("please input the password third:")
            if password == passwd:
                        print "login success"
            else:
                    print "you have no chance"
else:    
    print "username error"
 

      

本文出自 “12444546” 博客,谢绝转载!

用户登陆python脚本