真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

python怎么創(chuàng)建密碼-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“python怎么創(chuàng)建密碼”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)公司是一家以網(wǎng)絡(luò)技術(shù)公司,為中小企業(yè)提供網(wǎng)站維護(hù)、成都做網(wǎng)站、網(wǎng)站設(shè)計、網(wǎng)站備案、服務(wù)器租用、域名申請、軟件開發(fā)、微信小程序等企業(yè)互聯(lián)網(wǎng)相關(guān)業(yè)務(wù),是一家有著豐富的互聯(lián)網(wǎng)運(yùn)營推廣經(jīng)驗的科技公司,有著多年的網(wǎng)站建站經(jīng)驗,致力于幫助中小企業(yè)在互聯(lián)網(wǎng)讓打出自已的品牌和口碑,讓企業(yè)在互聯(lián)網(wǎng)上打開一個面向全國乃至全球的業(yè)務(wù)窗口:建站歡迎聯(lián)系:18982081108

使用:
    mkpass -l [password length] [-nu|-nl|-ns]
獲取幫助:
    mkpass -h

  1. #!/usr/bin/env python3

  2. # _*_coding:utf-8_*_

  3. # Auth by raysuen

  4. import sys,string,re

  5. import random

  6. class MakePass(object):

  7.     rPassInfo={

  8.         "Length":8,

  9.         "NoUpper":False,

  10.         "NoLower":False,

  11.         "NoSysbol":False

  12.            }

  13.     def __init__(self,passlen=8,nu=False,nl=False,ns=False):

  14.         if passlen != 8:

  15.             self.rPassInfo["Length"] = passlen

  16.         if nu == True:

  17.             self.rPassInfo["NoUpper"] = True

  18.         if nl == True:

  19.             self.rPassInfo["NoLower"] = True

  20.         if ns == True:

  21.             self.rPassInfo["NoSysbol"] = True

  22.     def MkPass(self):

  23.         rPassStr={

  24.             "passStr":'',

  25.             "AllChar":[],

  26.             "pwIndex":[],

  27.             "num":0

  28.         }

  29.         if self.rPassInfo["NoUpper"] == False:

  30.             rPassStr["AllChar"].append(random.choice(string.ascii_uppercase))

  31.             rPassStr["passStr"] = rPassStr["passStr"]+''.join(string.ascii_lowercase)

  32.             rPassStr["num"] += 1

  33.         if self.rPassInfo["NoLower"] == False:

  34.             rPassStr["AllChar"].append(random.choice(string.ascii_lowercase))

  35.             rPassStr["passStr"] = rPassStr["passStr"] + ''.join(string.ascii_lowercase)

  36.             rPassStr["num"] += 1

  37.         if self.rPassInfo["NoSysbol"] == False:

  38.             rPassStr["AllChar"].append(random.choice("!@#$%&*()+.,"))

  39.             rPassStr["passStr"] = rPassStr["passStr"] + "!@#$%&*()+.,"

  40.             rPassStr["num"] += 1

  41.         rPassStr["passStr"] = rPassStr["passStr"] + ''.join(string.digits)

  42.         rPassStr["AllChar"].append(random.choice(string.digits))

  43.         rPassStr["num"] += 1

  44.         rPassStr["pwIndex"].extend(random.sample(range(1,self.rPassInfo["Length"]),rPassStr["num"]))

  45.         rPassStr["pwIndex"].sort()

  46.         n = 0

  47.         i = 0

  48.         res = ''

  49.         while i < self.rPassInfo["Length"]:

  50.             isMatch = False

  51.             for j in rPassStr["pwIndex"]:

  52.                 if i == j:

  53.                     res = res + ''.join(rPassStr["AllChar"][n])

  54.                     n += 1

  55.                     i += 1

  56.                     isMatch = True

  57.                     break

  58.             if isMatch == False:

  59.                 res = res + ''.join(random.choice(rPassStr["passStr"]))

  60.                 i += 1

  61.         return res

  62. def func_help():

  63.     print("""

  64.         Name:

  65.             mkpass      --make password

  66.         

  67.         Synopsis:

  68.             mkpass -l [password length] [-nu|-nl|-ns]

  69.             

  70.         Description:

  71.             -l      Specify a number for the length of password,defaul 8

  72.             -nu     Don't use upper

  73.             -nl     Don't use lower

  74.             -ns     Don't use special character

  75.             -h      Get help

  76.     """)

  77. if __name__=='__main__':

  78.     i = 1

  79.     mp = MakePass()

  80.     while i < len(sys.argv):

  81.         if sys.argv[i] == '-l': #-l means length

  82.             if i+1 > len(sys.argv):

  83.                 print("The value of -l must be specified!!!")

  84.                 exit(1)

  85.             elif re.match("^-", sys.argv[i+1]) != None: #判斷下個參數(shù)是否以-開頭

  86.                 print("The value of -l must be specified!!!")

  87.                 exit(1)

  88.             elif sys.argv[i+1].isdecimal() == False: #判斷-l下一個參數(shù)是否為數(shù)字

  89.                 print("The value of -l must be digits")

  90.                 exit(1)

  91.             i += 1

  92.             mp.rPassInfo["Length"] = int(sys.argv[i]) #獲取-l參數(shù)的value

  93.         elif sys.argv[i] == '-nu': #-nu 指定不適用大寫字符

  94.             mp.rPassInfo["NoUpper"] = True

  95.         elif sys.argv[i] == '-nl': #-nu 指定不適用小寫字符

  96.             mp.rPassInfo["NoLower"] = True

  97.         elif sys.argv[i] == '-ns': #-nu 指定不適用特殊字符

  98.             mp.rPassInfo["NoSysbol"] = True

  99.         elif sys.argv[i] == '-h':

  100.             func_help()

  101.             exit(0)

  102.         i += 1

  103.     print(mp.MkPass())

“python怎么創(chuàng)建密碼”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!


本文標(biāo)題:python怎么創(chuàng)建密碼-創(chuàng)新互聯(lián)
鏈接分享:http://weahome.cn/article/dghjgo.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部