Password Generation - MS Graph

Ayan Usmani 151 Reputation points
2022-10-30T13:59:12.453+00:00

I am creating a user using MS API to create user. While doing so I am randomly generating a password via my python script which is being send in the api request body.

But it fails due to password not complying the complexity.

Is there any way to get random password genearated from MS api OR any suggested library in python which complies with MS password complexity policy.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,521 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dillon Silzer 54,286 Reputation points
    2022-10-30T19:50:52.22+00:00

    Hi @Ayan Usmani

    Password requirements:

    255407-image.png

    Cited from https://learn.microsoft.com/en-us/azure/active-directory/authentication/concept-sspr-policy

    Python:

    import random  
    import string  
      
    # get random password pf length 8 with letters, digits, and symbols  
    characters = string.ascii_letters + string.digits + string.punctuation  
    password = ''.join(random.choice(characters) for i in range(8))  
    print(password)  
    

    Cited from https://pynative.com/python-generate-random-string/

    Reference to Create User (Graph API):

    https://learn.microsoft.com/en-us/graph/api/user-post-users?view=graph-rest-1.0&tabs=http

    -------------------------------------------

    If this is helpful please accept answer.

    0 comments No comments

0 additional answers

Sort by: Most helpful