Python3实现生成随机密码的方法

WBOY
Release: 2016-06-16 08:42:35
Original
1315 people have browsed it

本文实例讲述了Python3实现生成随机密码的方法,在Python程序设计中有着广泛的实用价值。具体方法如下:

本文实例主要实现创建8位随机密码(大小写字母+数字),采用Python3生成了初级算法的随机密码。

主要功能代码如下:

__author__ = 'Goopand'

import string
import random

def genPassword(length=8,chars=string.digits+string.ascii_letters):
  return ''.join(random.sample(chars*10,8))

if __name__=="__main__":
  for i in range(10):
    print(genPassword(8))

Copy after login

希望本文所述实例对大家Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!