forked from clowder-framework/clowder
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-account.sh
More file actions
executable file
·56 lines (49 loc) · 1.61 KB
/
create-account.sh
File metadata and controls
executable file
·56 lines (49 loc) · 1.61 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
if [ -z "$1" ]; then
echo "parameter is empty(password)"
fi
IFS='%'
serviceName=$(echo $1 | tr '[:upper:]' '[:lower:]')
firstName=$serviceName
lastName="SERVICE"
fullName="$firstName $lastName"
emailaddress="[email protected]"
now=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
# only works on linux, not mac
#hasher=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 30)
#hasher=$(openssl rand -base64 30)
hasher=$(uuidgen | sed 's/-//g')
echo "Password for $serviceName is $hasher"
# htpasswd is used for bcrypt. It needs apache2-utils to be installed
#hasher_bcrypted=$(htpasswd -bnBC 10 "" "$hasher" | tr -d ':\n' | sed 's/^\$2y\$/\$2a\$/')
# can also use passlib, require `pip install passlib bcrypt`
hasher_bcrypted=$(python -c 'import sys, passlib.hash; print("$2a"+passlib.hash.bcrypt.encrypt(sys.argv[1], rounds=10)[3:])' "$hasher")
echo "Encrypted password is $hasher_bcrypted"
echo "db.social.users.remove({email: '$emailaddress'})
db.social.users.insert(
{
identityId: {
userId: '$serviceName',
providerId: 'userpass'
},
_typeHint : 'models.ClowderUser',
firstName: '$firstName',
lastName: '$lastName',
fullName: '$fullName',
email: '$emailaddress',
authMethod: {
_typeHint: 'securesocial.core.AuthenticationMethod',
method: 'userPassword'
},
passwordInfo: {
_typeHint: 'securesocial.core.PasswordInfo',
hasher: 'bcrypt',
password: '$hasher_bcrypted'
},
status : 'Active',
termsOfServices: {
accepted: true,
acceptedDate: ISODate('$now')
}
}, {w: 'majority', j: true});"
unset IFS