summaryrefslogtreecommitdiffstats
path: root/python/webiopi-passwd.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/webiopi-passwd.py')
-rwxr-xr-xpython/webiopi-passwd.py57
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
16import sys
17file = None
18
19print("WebIOPi passwd file generator")
20if 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()
30else:
31 file = "/etc/webiopi/passwd"
32
33f = open(file, "w")
34_LOGIN = "Enter Login: "
35_PASSWORD = "Enter Password: "
36_CONFIRM = "Confirm password: "
37_DONTMATCH = "Passwords don't match !"
38
39import getpass
40try:
41 login = raw_input(_LOGIN)
42except NameError:
43 login = input(_LOGIN)
44password = getpass.getpass(_PASSWORD)
45password2 = getpass.getpass(_CONFIRM)
46while password != password2:
47 print(_DONTMATCH)
48 password = getpass.getpass(_PASSWORD)
49 password2 = getpass.getpass(_CONFIRM)
50
51from webiopi.utils.crypto import encryptCredentials
52auth = encryptCredentials(login, password)
53print("\nHash: %s" % auth)
54if file:
55 f.write(auth)
56 f.close()
57 print("Saved to %s" % file)