Python generates random passwords

Source: Internet
Author: User

Python generates random cipher strings


The random module of Python can generate stochastic numbers, mostly using this to generate random passwords.

string module: string.letters,string.printable,string.printable


>>> import string>>> string.letters ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ' > >> string.digits ' 0123456789 ' >>> string.printable ' 0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz! " #$%&\ ' () *+,-./:;<=>[email protected][\\]^_ ' {|} ~ \t\n\r\x0b\x0c '



Here's a random number generation method that randomly generates 10 groups of numbers, uppercase and lowercase letters, and you can specify the length of the random number:


#!/usr/bin/env python #-*- coding:utf-8 -*-" Generate random passwords briefly, including uppercase and lowercase letters, numbers, and can specify password length # generate random password ' ' in Import randomimport string#python3 for String.ascii_letters, The python2 can be used with string.letters and String.ascii_lettersdef genpassword (length):     chars= string.ascii_letters+string.digits    return  '. Join ([Random.choice (chars)  for  i in range (length)])      "     #得出的结果中字符会有重复的       #return   ". Join (Random.sample (chars, 15)) #得出的结果中字符不会有重复的      ' ' if __name__== ' __main__ ':     ' #生成10个随机密码    '     for  i in range (:          #密码的长度为15          print genpassword () 


Python passwd.py Bdmxufzf5ktyhjjedqijymjob7or2tpbkk58ptwqiwf9zpufypnwbmx9msyw9rna9d8oxebjs7sdh2fefkhqouxj9fwzrnrc0k94yn8ksmshewb2lezxeavir Bqf7c6vjprln6z99a3zyw37cb7bej


This article from "~" blog, declined reprint!

Python generates random passwords

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.