-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.py
More file actions
42 lines (33 loc) · 1.06 KB
/
users.py
File metadata and controls
42 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import bcrypt
import os
import boto3
from boto3.dynamodb.conditions import Key, Attr
# https://boto3.readthedocs.org/en/latest/guide/dynamodb.html
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('ec2.clive.io-subdomains')
def getAllUsers():
def createUser(username, password):
passsalt = bcrypt.gensalt()
if userExists(username):
return False
else:
table.put_item(Item={
'username': username,
'passhash': bcrypt.hashpw(password, passsalt),
'passsalt': passsalt
})
return True
def userExists(username):
response = table.query(KeyConditionExpression=Key('username').eq(username))
return len(response['Items']) > 0
def passMatches(username, password):
userinfo = getUserInfo(username)
return bcrypt.hashpw(password, userinfo['passsalt']) == userinfo['passhash']
def getUserInfo(username):
return table.query(KeyConditionExpression=Key('username').eq(username))['Items'][0]
def deleteUser(username):
if userExists(username):
table.delete_item(Key={'username':username})
return True
else:
return False