Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cf8abcbe
Commit
cf8abcbe
authored
May 19, 2018
by
Daniel Chimeno
Committed by
stevendaprano
May 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import secrets module in secrets recipes (#6705)
parent
f65e31fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
Doc/library/secrets.rst
Doc/library/secrets.rst
+8
-4
No files found.
Doc/library/secrets.rst
View file @
cf8abcbe
...
...
@@ -145,8 +145,9 @@ Generate an eight-character alphanumeric password:
.. testcode::
import string
import secrets
alphabet = string.ascii_letters + string.digits
password = ''.join(choice(alphabet) for i in range(8))
password = ''.join(
secrets.
choice(alphabet) for i in range(8))
.. note::
...
...
@@ -164,9 +165,10 @@ three digits:
.. testcode::
import string
import secrets
alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(choice(alphabet) for i in range(10))
password = ''.join(
secrets.
choice(alphabet) for i in range(10))
if (any(c.islower() for c in password)
and any(c.isupper() for c in password)
and sum(c.isdigit() for c in password) >= 3):
...
...
@@ -177,11 +179,12 @@ Generate an `XKCD-style passphrase <https://xkcd.com/936/>`_:
.. testcode::
import secrets
# On standard Linux systems, use a convenient dictionary file.
# Other platforms may need to provide their own word-list.
with open('/usr/share/dict/words') as f:
words = [word.strip() for word in f]
password = ' '.join(choice(words) for i in range(4))
password = ' '.join(
secrets.
choice(words) for i in range(4))
Generate a hard-to-guess temporary URL containing a security token
...
...
@@ -189,7 +192,8 @@ suitable for password recovery applications:
.. testcode::
url = 'https://mydomain.com/reset=' + token_urlsafe()
import secrets
url = 'https://mydomain.com/reset=' + secrets.token_urlsafe()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment