private static Microsoft.SqlServer.Management.Smo.Login ConstructLogin(LoginProperties loginProperties, Server server) { var login = new Microsoft.SqlServer.Management.Smo.Login(server._server, loginProperties.Name) { LoginType = loginProperties.LoginType, Sid = loginProperties.Sid, DefaultDatabase = loginProperties.DefaultDatabase }; if (loginProperties.LoginType == LoginType.SqlLogin) { if (loginProperties.PasswordHash != null) { login.Create(loginProperties.PasswordHash, LoginCreateOptions.IsHashed); } else if (loginProperties.Password != null) { login.Create(loginProperties.Password); } else { throw new ArgumentException("Password or hash was not supplied for sql login."); } } else { login.Create(); } return(login); }
/// <summary> /// Creates a new login on the server. /// </summary> /// <param name="loginProperties">Values for login initialization</param> /// <param name="server">The server to create the login on</param> public Login(LoginProperties loginProperties, Server server) { _server = server; _login = _server.ConstructLogin(loginProperties.Name); _login.LoginType = loginProperties.LoginType; _login.Sid = loginProperties.Sid; _login.DefaultDatabase = loginProperties.DefaultDatabase; if (loginProperties.LoginType == Smo.LoginType.SqlLogin) { if (loginProperties.PasswordHash != null) { _login.Create(loginProperties.PasswordHash, Smo.LoginCreateOptions.IsHashed); } else if (loginProperties.Password != null) { _login.Create(loginProperties.Password); } else { throw new ArgumentException("Password or hash was not supplied for sql login."); } } else { _login.Create(); } }
public void AddLogin(LoginProperties login) { var matchingLogin = Logins.SingleOrDefault(l => l.Name.Equals(login.Name, StringComparison.InvariantCultureIgnoreCase)); if (matchingLogin == null) { matchingLogin = new Login(login, this); } }
public void AddRole(LoginProperties login, RoleProperties role) { var matchingLogin = Logins.SingleOrDefault(l => l.Name.Equals(login.Name, StringComparison.InvariantCultureIgnoreCase)); if (matchingLogin == null) { throw new Exception("No matching login found"); } matchingLogin.AddRole(role.Name); }
public void DropLogin(LoginProperties login) { _server.Logins[login.Name].DropIfExists(); }
/// <summary> /// Creates a new login on the server. /// </summary> /// <param name="loginProperties">Values for login initialization</param> /// <param name="server">The server to create the login on</param> public Login(LoginProperties loginProperties, Server server) { _server = server; _login = ConstructLogin(loginProperties, server); }