Python generates random password strings

Source: Internet
Author: User

Today, I want to change the server password. I don't know what password to set. Set a random number simply. The random module in python can generate random numbers. This is mainly used to generate random passwords.

By the way, there are three functions in the string module: string. letters, string. printable, string. printable. Below are the outputs of these functions. You can take a look at them. You don't need to talk about them more:

1234567 >>>> importstring >>> string. letters 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz '>>> string. digits '000000' >>> string. printable' success! "# $ % & \ '() * +,-./:; <=>? @ [\] ^ _ '{| }~ \ T \ n \ r \ x0b \ x0c'

The following describes how to randomly generate 10 groups of random numbers containing numbers and uppercase/lowercase letters. You can specify the length of a random number:

1234567891011121314151617 #-*-coding: UTF-8-*-''' generate a random password briefly, including uppercase and lowercase letters and numbers, you can specify the password length ''' # generate the random password importrandomimportstring # string in python3. ascii_letters, and string can be used in python2. letters and string. ascii_lettersdefGenPassword (length): chars = string. ascii_letters + string. digitsreturn ''. join ([random. choice (chars) foriinrange (length)]) # The returned result contains repeated characters # return ''. join (random. sample (chars, 15) # No repeated if _ name __= = "_ main _" characters exist in the result __": # generate 10 random passwords foriinrange (10): # The password length is 15 printGenPassword (15)

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.