1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-10-30 05:57:05 +01:00
doorlockd-mirror/doorlockd-passwd
Ralf Ramsauer 45724f37c8 doorlockd: backend: support local authentication
Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
2018-09-18 01:28:34 +02:00

41 lines
988 B
Python
Executable File

#!/usr/bin/env python3
"""
Doorlockd -- Binary Kitchen's smart door opener
Copyright (c) Binary Kitchen e.V., 2018
Author:
Ralf Ramsauer <ralf@binary-kitchen.de>
This work is licensed under the terms of the GNU GPL, version 2. See
the LICENSE file in the top-level directory.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
"""
import getpass
import hashlib
import uuid
import sys
if len(sys.argv) != 3:
print('Usage: %s db username' % sys.argv[0])
quit(-1)
username = sys.argv[2]
try:
password = getpass.getpass()
except Exception as error:
print('ERROR', error)
quit(-1)
salt = uuid.uuid4().hex
password = hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt
with open(sys.argv[1], 'a') as file:
file.write('%s %s\n' % (username, password))