码迷,mamicode.com
首页 > 编程语言 > 详细

python运维开发实践--Day1

时间:2016-06-23 19:05:32      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:python2.7 运维开发

一、脚本功能

登录接口

 -输入用户名、密码

 -用户名、密码为空,提示

 -输错三次锁定

 -认证成功后,显示欢迎登录信息

二、流程图

技术分享

三、python代码

[root@s01-ansible-106-k3 Day1]# cat login.py 

#!/usr/bin/env python

import sys

username = ‘hanyun‘

password = ‘hanyun123‘

retry_count = 0

while True:

  user = raw_input(‘Username:‘).strip()

  if len(user) == 0:

    print ‘Username cannot be empty!‘

    continue

  passwd = raw_input(‘Password:‘).strip()

  if len(passwd) == 0:

     print ‘Password cannot be empty!‘

     continue

#handle the username and passwd empty issue


#going to the loging verificaiton part

  if user == username and passwd == password:

    print ‘welcome %s login our system!‘ % user

    break

  else:

    retry_count += 1

    print ‘Wrong username or password,you have %s more chances!‘ % (3 - retry_count) 

    if retry_count == 3: 

      print ‘Your username is locked!‘

      sys.exit()

四、功能演示

[root@s01-ansible-106-k3 Day1]# python login.py 

Username:fdsaf

Password:cdsaf

Wrong username or password,you have 2 more chances!

Username:ada

Password:cdfd

Wrong username or password,you have 1 more chances!

Username:adfsa

Password:333

Wrong username or password,you have 0 more chances!

Your username is locked!


[root@s01-ansible-106-k3 Day1]# python login.py 

Username:afc

Password:123

Wrong username or password,you have 2 more chances!

Username:hanyun

Password:hanyun123

welcome hanyun login our system!


[root@s01-ansible-106-k3 Day1]# python login.py 

Username:

Username cannot be empty!

Username:fdsfa

Password:dsf

Wrong username or password,you have 2 more chances!

Username:aa

Password:

Password cannot be empty!

Username:

本文出自 “hanyun.fang” 博客,转载请与作者联系!

python运维开发实践--Day1

标签:python2.7 运维开发

原文地址:http://hanyun.blog.51cto.com/1060170/1792245

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!