python运维开发实践--Day1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python运维开发实践--Day1相关的知识,希望对你有一定的参考价值。

一、脚本功能

登录接口

 -输入用户名、密码

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

 -输错三次锁定

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

二、流程图

技术分享

三、python代码

[[email protected] 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()

四、功能演示

[[email protected] 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!


[[email protected] 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!


[[email protected] 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的主要内容,如果未能解决你的问题,请参考以下文章

基础入门_Python-模块和包.运维开发中inspect自省模块的最佳实践?

基础入门_Python-模块和包.运维开发中chartdet编码检测的最佳实践?

python运维开发实践--Day2

基础入门_Python-内建函数.运维开发中eval内建函数的最佳实践?

基础入门_Python-模块和包.运维开发中内建模块getopt的最佳实践?

基础入门_Python-模块和包.运维开发中__import__动态导入最佳实践?