python運維開發實踐--Day1

一、腳本功能

登錄接口

 -輸入用戶名、密碼

 -用戶名、密碼爲空,提示

 -輸錯三次鎖定

 -認證成功後,顯示歡迎登錄信息

二、流程圖

wKioL1droTiiZSgUAADPxDw7k7o037.png-wh_50

三、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:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章