Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block for arbitrary username with password. If the user exists, change the existing password #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions adduserpass/adduserpass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "adduserpass",
"text": "Add %1 user\\n with password %2",
"script": "adduserpass.py",
"args": [
{
"type":"text",
"default":"newuser",
"maxLength":0
},
{
"type": "text",
"default": "newpass",
"maxLength":0
}
],
"network": false,
"continue": true,
"type": "setting",
"category":"setting",
"supportedOperatingSystems": [
"raspbian-pibakery.img",
"raspbian-lite-pibakery.img"
],
"shortDescription":"Add a user with password or change password",
"longDescription":"If the user doesn't exists, this will add a user(with home dir and group). If the user exists, change the password."
}
21 changes: 21 additions & 0 deletions adduserpass/adduserpass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python
# Thanks to Filipe Pina on StackOverflow

import subprocess,crypt,random, sys

login = sys.argv[1]
password = sys.argv[2]

ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./"
salt = ''.join(random.choice(ALPHABET) for i in range(16))

shadow_password = crypt.crypt(password,'$6$'+salt+'$')

r = subprocess.call(('useradd', '-m', '-U', login))
if r ==9:
print 'Username in use for '+login+', changing password'

r = subprocess.call(('usermod', '-p', shadow_password, login))

if r != 0:
print 'Error changing password for ' + login
1 change: 1 addition & 0 deletions info.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"otgremove",
"bootbehaviour",
"changepass",
"adduserpass",
"sethostname",
"newcronjob",
"uartconsole",
Expand Down