This example shares the implementation process of generating random passwords in Python for your reference. The specific content is as follows
Written a program, mainly used to detect empty passwords and weak passwords in the MySQL database For passwords,
here, three types of weak passwords are defined:
1. Continuous numbers , such as 123456, implemented in get_weak_num
2. Continuous letters , such as abcdef, are implemented in get_weak_character
. Of course, the number is random.
3. Random combination of numbers and letters. Implemented in get_weak_num_character.
At the same time, a list of password_exist is defined to save different passwords. If the newly generated password exists in the list, the connection to the MySQL database will not be performed and it will go directly to the next cycle.
The details are as follows:
#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~'
The above is the entire content of this article, I hope it will be helpful to everyone's study.
For more related articles on how to generate random passwords in Python, please pay attention to the PHP Chinese website!

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

InPython,listsusedynamicmemoryallocationwithover-allocation,whileNumPyarraysallocatefixedmemory.1)Listsallocatemorememorythanneededinitially,resizingwhennecessary.2)NumPyarraysallocateexactmemoryforelements,offeringpredictableusagebutlessflexibility.

InPython, YouCansSpectHedatatYPeyFeLeMeReModelerErnSpAnT.1) UsenPyNeRnRump.1) UsenPyNeRp.DLOATP.PLOATM64, Formor PrecisconTrolatatypes.

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

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

NumPyallowsforvariousoperationsonarrays:1)Basicarithmeticlikeaddition,subtraction,multiplication,anddivision;2)Advancedoperationssuchasmatrixmultiplication;3)Element-wiseoperationswithoutexplicitloops;4)Arrayindexingandslicingfordatamanipulation;5)Ag

ArraysinPython,particularlythroughNumPyandPandas,areessentialfordataanalysis,offeringspeedandefficiency.1)NumPyarraysenableefficienthandlingoflargedatasetsandcomplexoperationslikemovingaverages.2)PandasextendsNumPy'scapabilitieswithDataFramesforstruc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools
