本位实例为大家分享了Python生成随机密码的实现过程,供大家参考,具体内容如下
写了个程序,主要是用来检测MySQL数据库的空密码和弱密码的,
在这里,定义了三类弱密码:
1. 连续数字,譬如123456,在get_weak_num中实现
2. 连续字母,譬如abcdef,在get_weak_character中实现
当然,个数都是随机的。
3. 数字和字母随机组合。在get_weak_num_character中实现。
同时定义了一个password_exist的列表,用于保存不同的密码。如果新生成的密码在列表中存在,则不进行MySQL数据库的连接,直接到下一次循环。
具体如下:
#coding=utf8 import random,string,MySQLdb def get_num(): return random.randint(0,9) def get_char(): return random.choice(tuple(string.lowercase)) def choose_any(): return [str(get_num()),get_char()] def get_weak_num(): weak_num=[] initial_num=get_num() for i in range(get_num()): weak_num.append(str(initial_num+i)) if initial_num +i ==9: break; return weak_num def get_weak_character(): weak_character=[] initial_character=get_char() for i in range(get_num()): weak_character.append(chr(ord(initial_character)+i)) if chr(ord(initial_character)+i) == 'z': break return weak_character def get_weak_num_character(): return [random.choice(choose_any()) for num in range(get_num())] password_exist=[] for i in range(10000): choice = [get_weak_num(), get_weak_character(), get_weak_num_character()] password=''.join(random.choice(choice)) print "第"+str(i)+"次密码为:"+password if password in password_exist: continue else: try: MySQLdb.connect('192.168.244.145', 'root', password) print 'The password for MySQL is:'+password break except: continue password_exist.append(password) if i == 9999: print 'The password is not so weak~'
以上就是本文的全部内容,希望对大家的学习有所帮助。
更多Python如何生成随机密码的方法相关文章请关注PHP中文网!

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,减法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)

列表sandnumpyArraysInpyThonHavedIfferentMemoryfootprints:listSaremoreFlexibleButlessMemory-效率,而alenumpyArraySareSareOptimizedFornumericalData.1)listsStorReereReereReereReereFerenceStoObjects,withoverHeadeBheadaroundAroundaroundaround64bytaround64bitson64-bitsysysysyssyssyssyssyssyssysssys2)

toensurepythonscriptsbehavecorrectlyacrycrossdevelvermations,登台和生产,USETHESTERTATE:1)Environment varriablesforsimplesettings,2)configurationFilesForefilesForcomPlexSetups,3)dynamiCofforAdaptapity.eachmethodofferSuniquebeneiquebeneiquebeneniqueBenefitsaniqueBenefitsandrefitsandRequiresandRequireSandRequireSca

Python列表切片的基本语法是list[start:stop:step]。1.start是包含的第一个元素索引,2.stop是排除的第一个元素索引,3.step决定元素之间的步长。切片不仅用于提取数据,还可以修改和反转列表。

ListSoutPerformarRaysin:1)DynamicsizicsizingandFrequentInsertions/删除,2)储存的二聚体和3)MemoryFeliceFiceForceforseforsparsedata,butmayhaveslightperformancecostsinclentoperations。

toConvertapythonarraytoalist,usEthelist()constructororageneratorexpression.1)intimpthearraymoduleandcreateanArray.2)USELIST(ARR)或[XFORXINARR] to ConconverTittoalist,请考虑performorefformanceandmemoryfformanceandmemoryfformienceforlargedAtasetset。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

记事本++7.3.1
好用且免费的代码编辑器