Beispiel #1
0
        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);
        }
Beispiel #2
0
 /// <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();
     }
 }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
 public void DropLogin(LoginProperties login)
 {
     _server.Logins[login.Name].DropIfExists();
 }
Beispiel #6
0
 /// <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);
 }