Guest User

Untitled

a guest
Oct 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. /// <summary>
  2. /// Creates user.
  3. /// </summary>
  4. /// <param name="name">User name.</param>
  5. /// <returns>Newly created user.</returns>
  6. public IPrincipal CreatePrincipal(string name)
  7. {
  8. if (!PrincipalBase.IsValidUserName(name))
  9. {
  10. throw new DavException("User name contains invalid characters", DavStatus.FORBIDDEN);
  11. }
  12.  
  13. var userPrincipal = new UserPrincipal(Context.GetPrincipalContext());
  14.  
  15. userPrincipal.Name = name;
  16. userPrincipal.UserPrincipalName = name;
  17.  
  18. userPrincipal.Enabled = true;
  19. userPrincipal.ExpirePasswordNow();
  20.  
  21. Context.PrincipalOperation(userPrincipal.Save);
  22.  
  23. return new User(userPrincipal, Context);
  24. }
Add Comment
Please, Sign In to add comment