当前位置: 移动技术网 > IT编程>脚本编程>Python > Python登录脚本(代码)

Python登录脚本(代码)

2018年02月10日  | 移动技术网IT编程  | 我要评论

副镇长述职述廉报告,郑中基,康熙皇帝的儿子

Python登录脚本(代码)

#!/usr/bin/env python
import sys              ##导入该模块
while True:
    user = raw_input('Username:').strip()   ##输入user,并且去除前后的空格
    if len(user) == 0:       ##如果user的长度为0,则重新输入
        print "please input sb. name!"
        continue
    break
password = raw_input('Password:').strip()   ##输入密码

username = ["fentiao","baicai"]
Password = ["fentiao","baicai"]
b = 0 
c = 0
for I in (0,1):
    if user == username[I] and  Password[I] == password :      ##如果账户和密码对应都正确,则登录成功
            sys.exit("login success")
    elif user == username[I] and Password[I] != password :     ##如果,账户正确,密码错误
            print "Password is wrong!"
    else:            ##如果user不存在,则输入。
        b = b + 1
        if b == 2:
            print "user is not exit!"

2:

import sys
username = 'alex'
password = 'alex123'
locked = 1              ##locked为1代表没锁,为0代表上锁 

retry_counter = 0

while retry_counter <3 :     
  user = raw_input('Username:').strip()  ##输入user
  if len(user) ==0:
    print '\033[31;1mUsername cannot be empty!\033[0m'      ##user不能为空
    continue
  passwd = raw_input('Password:').strip()  
  if len(passwd) == 0:
    print '\033[31;1mPassword cannot be empty!\033[0m'
    continue                      ##输入密码,不能为空

  #handle the username and passwd empty issue

  #going to the loging verification part

  if locked == 0:#means the user is locekd 
    print 'Your username is locked!'
    sys.exit()               ##判断是否上锁,上锁则退出

  else:
    if user == username  and passwd == password:
      #means passed the verfification
      sys.exit('Welcome %s login to our system!' % user )               ##如过密码账号都正确,登录成功

    else:
      #retry_counter = retry_counter + 1
      retry_counter += 1     ##否则,还有x次登录机会
      print '\033[31;1mWrong username or password, you have %s more chances!\033[0m' % (3 - retry_counter  )

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网