diff options
Diffstat (limited to 'python/webiopi-passwd.py')
| -rwxr-xr-x | python/webiopi-passwd.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/python/webiopi-passwd.py b/python/webiopi-passwd.py new file mode 100755 index 0000000..7c0fbff --- /dev/null +++ b/python/webiopi-passwd.py | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | # Copyright 2012-2013 Eric Ptak - trouch.com | ||
| 3 | # | ||
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | # you may not use this file except in compliance with the License. | ||
| 6 | # You may obtain a copy of the License at | ||
| 7 | # | ||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | # | ||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | # See the License for the specific language governing permissions and | ||
| 14 | # limitations under the License. | ||
| 15 | |||
| 16 | import sys | ||
| 17 | file = None | ||
| 18 | |||
| 19 | print("WebIOPi passwd file generator") | ||
| 20 | if len(sys.argv) == 2: | ||
| 21 | file = sys.argv[1] | ||
| 22 | if file == "--help" or file == "-h": | ||
| 23 | print("Usage: webiopi-passwd [--help|file]") | ||
| 24 | print("Compute and display hash used by WebIOPi for Authentication") | ||
| 25 | print("Login and Password are prompted") | ||
| 26 | print("\t--help\tDisplay this help") | ||
| 27 | print("\t-h") | ||
| 28 | print("\tfile\tSave hash to file") | ||
| 29 | sys.exit() | ||
| 30 | else: | ||
| 31 | file = "/etc/webiopi/passwd" | ||
| 32 | |||
| 33 | f = open(file, "w") | ||
| 34 | _LOGIN = "Enter Login: " | ||
| 35 | _PASSWORD = "Enter Password: " | ||
| 36 | _CONFIRM = "Confirm password: " | ||
| 37 | _DONTMATCH = "Passwords don't match !" | ||
| 38 | |||
| 39 | import getpass | ||
| 40 | try: | ||
| 41 | login = raw_input(_LOGIN) | ||
| 42 | except NameError: | ||
| 43 | login = input(_LOGIN) | ||
| 44 | password = getpass.getpass(_PASSWORD) | ||
| 45 | password2 = getpass.getpass(_CONFIRM) | ||
| 46 | while password != password2: | ||
| 47 | print(_DONTMATCH) | ||
| 48 | password = getpass.getpass(_PASSWORD) | ||
| 49 | password2 = getpass.getpass(_CONFIRM) | ||
| 50 | |||
| 51 | from webiopi.utils.crypto import encryptCredentials | ||
| 52 | auth = encryptCredentials(login, password) | ||
| 53 | print("\nHash: %s" % auth) | ||
| 54 | if file: | ||
| 55 | f.write(auth) | ||
| 56 | f.close() | ||
| 57 | print("Saved to %s" % file) | ||
