1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-03-17 17:57:23 +01:00

admin: update user's password from the admin

This commit is contained in:
Joshua Tauberer
2014-09-21 17:24:01 +00:00
parent 8dfbb90f3a
commit 846768efcb
4 changed files with 59 additions and 11 deletions

View File

@@ -139,13 +139,7 @@ def add_mail_user(email, pw, privs, env):
if not validate_email(email, mode='user'):
return ("Invalid email address.", 400)
# validate password
if pw.strip() == "":
return ("No password provided.", 400)
if re.search(r"[\s]", pw):
return ("Passwords cannot contain spaces.", 400)
if len(pw) < 4:
return ("Passwords must be at least four characters.", 400)
validate_password(pw)
# validate privileges
if privs is None or privs.strip() == "":
@@ -193,6 +187,8 @@ def add_mail_user(email, pw, privs, env):
return kick(env, "mail user added")
def set_mail_password(email, pw, env):
validate_password(pw)
# hash the password
pw = utils.shell('check_output', ["/usr/bin/doveadm", "pw", "-s", "SHA512-CRYPT", "-p", pw]).strip()
@@ -386,6 +382,16 @@ def kick(env, mail_result=None):
return "".join(s for s in results if s != "")
def validate_password(pw):
# validate password
if pw.strip() == "":
raise ValueError("No password provided.")
if re.search(r"[\s]", pw):
raise ValueError("Passwords cannot contain spaces.")
if len(pw) < 4:
raise ValueError("Passwords must be at least four characters.")
if __name__ == "__main__":
import sys
if len(sys.argv) > 2 and sys.argv[1] == "validate-email":