1
Default a password across and entire domain.
Question asked by Edward Green - 4/30/2023 at 8:02 PM
Answered
Is it possible to set a default password across an entire domain?

1 Reply

Reply to Thread
1
Zach Sylvester Replied
Employee Post Marked As Answer
Hey Edward, 

Thanks for reaching out with this question. 
There is no way to mass-set a password for a given domain. 
But I made a script that allows you to set this. 
To use this you will just need to enter in the primary domain admin's email address and password. (Each domain has its own domain admin) After this, you just replace the 'What you want to set the users to' with whatever you want to set the user's passwords to. If you open a ticket I can answer any questions you might have about this. 
See below. 
import requests

global url


def auth(username, password):
    authurl = url + "/api/v1/auth/authenticate-user" 
    myobj = {'username': username, 'password':password} 
    data = requests.post(authurl, data = myobj) # this posts the username and password to the api
    #print(data.json())
    refreshToken = data.json()['refreshToken'] # this is the refresh token
    accessToken = data.json()['accessToken'] # this is the access token
    accessTokenExpiration = data.json()['accessTokenExpiration'] # this is the access token expiration date
    access_info = {'accessToken': accessToken, 'accessTokenExpiration': accessTokenExpiration, 'refreshToken': refreshToken} # this is the access token, refresh token and expiration info
    return access_info # returns the information


def update_password(email, password, access_info):
    authurl = url + "/api/v1/settings/domain/post-user"
    data ={"email":email,"userData":{"password":password}}
    response = requests.post(authurl, headers={'Authorization': 'Bearer ' + access_info['accessToken']}, json=data)
    print(response.json())
    return response.json()


def list_users(access_info):
    authurl = url + "/api/v1/settings/domain/list-users"
    data = requests.get(authurl, headers={'Authorization': 'Bearer ' + access_info['accessToken']})
    #print(data.json())
    emaillist = []
    for emailAddress in data.json()['userData']:
        emaillist.append(emailAddress['emailAddress'])
    return emaillist

if __name__ == "__main__":
    
    # Set these variables
    url = "https://mail.yourhostname.com";
    domain_admin_email = 'admin@example.com'
    domain_admin_password = 'DOMAIN_ADMIN_PASSWORD'
    password_to_set = 'What you want to set the users to'
    ###############################################
    
    auth = auth(domain_admin_email, domain_admin_password)
    users = list_users(auth)
    for user in users:
        if user != domain_admin_email:
            print(user)
            update_password(user, password_to_set, auth)
Thanks, 
Zach Sylvester Software Developer SmarterTools Inc. www.smartertools.com

Reply to Thread