Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
264cb144
Unverified
Commit
264cb144
authored
6 years ago
by
Amber Brown
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Port hash_password to Python 3 (#4161)
* port hash_password * changelog
parent
b3708830
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/4161.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/4161.bugfix
scripts/hash_password
+34
-7
34 additions, 7 deletions
scripts/hash_password
tox.ini
+1
-1
1 addition, 1 deletion
tox.ini
with
36 additions
and
8 deletions
changelog.d/4161.bugfix
0 → 100644
+
1
−
0
View file @
264cb144
The hash_password script now works on Python 3.
This diff is collapsed.
Click to expand it.
scripts/hash_password
+
34
−
7
View file @
264cb144
...
@@ -3,13 +3,15 @@
...
@@ -3,13 +3,15 @@
import
argparse
import
argparse
import
getpass
import
getpass
import
sys
import
sys
import
unicodedata
import
bcrypt
import
bcrypt
import
yaml
import
yaml
bcrypt_rounds
=
12
bcrypt_rounds
=
12
password_pepper
=
""
password_pepper
=
""
def
prompt_for_pass
():
def
prompt_for_pass
():
password
=
getpass
.
getpass
(
"
Password:
"
)
password
=
getpass
.
getpass
(
"
Password:
"
)
...
@@ -23,19 +25,27 @@ def prompt_for_pass():
...
@@ -23,19 +25,27 @@ def prompt_for_pass():
return
password
return
password
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
"
Calculate the hash of a new password, so that passwords
"
description
=
(
"
can be reset
"
)
"
Calculate the hash of a new password, so that passwords can be reset
"
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
-p
"
,
"
--password
"
,
"
-p
"
,
"
--password
"
,
default
=
None
,
default
=
None
,
help
=
"
New password for user. Will prompt if omitted.
"
,
help
=
"
New password for user. Will prompt if omitted.
"
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
-c
"
,
"
--config
"
,
"
-c
"
,
"
--config
"
,
type
=
argparse
.
FileType
(
'
r
'
),
type
=
argparse
.
FileType
(
'
r
'
),
help
=
"
Path to server config file. Used to read in bcrypt_rounds and password_pepper.
"
,
help
=
(
"
Path to server config file.
"
"
Used to read in bcrypt_rounds and password_pepper.
"
),
)
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -49,4 +59,21 @@ if __name__ == "__main__":
...
@@ -49,4 +59,21 @@ if __name__ == "__main__":
if
not
password
:
if
not
password
:
password
=
prompt_for_pass
()
password
=
prompt_for_pass
()
print
bcrypt
.
hashpw
(
password
+
password_pepper
,
bcrypt
.
gensalt
(
bcrypt_rounds
))
# On Python 2, make sure we decode it to Unicode before we normalise it
if
isinstance
(
password
,
bytes
):
try
:
password
=
password
.
decode
(
sys
.
stdin
.
encoding
)
except
UnicodeDecodeError
:
print
(
"
ERROR! Your password is not decodable using your terminal encoding (%s).
"
%
(
sys
.
stdin
.
encoding
,)
)
pw
=
unicodedata
.
normalize
(
"
NFKC
"
,
password
)
hashed
=
bcrypt
.
hashpw
(
pw
.
encode
(
'
utf8
'
)
+
password_pepper
.
encode
(
"
utf8
"
),
bcrypt
.
gensalt
(
bcrypt_rounds
),
).
decode
(
'
ascii
'
)
print
(
hashed
)
This diff is collapsed.
Click to expand it.
tox.ini
+
1
−
1
View file @
264cb144
...
@@ -122,7 +122,7 @@ skip_install = True
...
@@ -122,7 +122,7 @@ skip_install = True
basepython
=
python3.6
basepython
=
python3.6
deps
=
deps
=
flake8
flake8
commands
=
/bin/sh -c "flake8 synapse tests scripts scripts-dev scripts/register_new_matrix_user scripts/synapse_port_db synctl {env:PEP8SUFFIX:}"
commands
=
/bin/sh -c "flake8 synapse tests scripts scripts-dev
scripts/hash_password
scripts/register_new_matrix_user scripts/synapse_port_db synctl {env:PEP8SUFFIX:}"
[testenv:check_isort]
[testenv:check_isort]
skip_install
=
True
skip_install
=
True
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment