/// <summary> /// Adds a new SQL Server login /// </summary> /// <param name="name">The name for the new login</param> /// <param name="type">By default, a login is created for use by SQL Server Authentication. Alternately specify the login type to map a Microsoft Windows NT 4.0 or Microsoft Windows 2000 user or group.</param> /// <param name="password">The password.</param> /// <returns>A new SqlLogin Object</returns> public SqlLogin Add(string name, SqlLoginType type, string password) { // Validation if (name == null || name.Length == 0) { throw new ArgumentException(SR.GetString("SqlLogin_MustHaveValidName")); } if (this[name] != null) { throw new ArgumentException(String.Format(SR.GetString("SqlLogin_NameAlreadyExists"), name)); } // Physically add server NativeMethods.ILogin dmoLogin = (NativeMethods.ILogin) new NativeMethods.Login(); dmoLogin.SetName(name); dmoLogin.SetType((int)type); if (type == SqlLoginType.Standard) { dmoLogin.SetPassword(string.Empty, password); } this.server.dmoServer.GetLogins().Add(dmoLogin); SqlLogin login = new SqlLogin(this.server, dmoLogin.GetName(), (SqlLoginType)dmoLogin.GetType(), (SqlNtAccessType)dmoLogin.GetNTLoginAccessType(), dmoLogin.GetDatabase(), dmoLogin.GetLanguage(), dmoLogin.GetLanguageAlias()); login.dmoLogin = dmoLogin; this.sqlLogins.Add(login); return(login); }
internal SqlLogin(SqlServer server, string name, SqlLoginType loginType, SqlNtAccessType nTLoginAccessType, string database, string defaultLanguage, string languageAlias) { this.server = server; this.name = name; this.loginType = loginType; this.database = database; this.nTLoginAccessType = nTLoginAccessType; this.language = defaultLanguage; this.languageAlias = languageAlias; }
/// <summary> /// Updates the SqlLoginCollection with any changes made since the last call to Refresh. /// Refresh is automatically called once when the SqlTable.sqlLogins collection is read. /// </summary> public void Refresh() { server.dmoServer.GetLogins().Refresh(false); sqlLogins = new ArrayList(); for (int i = 0; i < server.dmoServer.GetLogins().GetCount(); i++) { SqlLogin login; NativeMethods.ILogin dmoLogin = null; dmoLogin = server.dmoServer.GetLogins().Item(i + 1); SqlLoginType type = (SqlLoginType)dmoLogin.GetType(); SqlNtAccessType ntlogin = (SqlNtAccessType)dmoLogin.GetNTLoginAccessType(); login = new SqlLogin(this.server, dmoLogin.GetName(), type, ntlogin, dmoLogin.GetDatabase(), dmoLogin.GetLanguage(), dmoLogin.GetLanguageAlias()); sqlLogins.Add(login); login.dmoLogin = dmoLogin; } }
/// <summary> /// Used for forms auth. currently aren't using. /// </summary> /// <param name="username">The username of the current user</param> /// <param name="password">The password of the current user</param> /// <param name="persist">Should we persist this data</param> /// <param name="loginType">What type of login</param> public void WriteCookieForFormsAuthentication(string username, string password, bool persist, SqlLoginType loginType) { //Create the ticket, and add the groups. bool isCookiePersistent = persist; string userData = null; userData = password + "," + loginType.ToString(); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(60), isCookiePersistent, userData); //Encrypt the ticket. String encryptedTicket = FormsAuthentication.Encrypt(authTicket); //Create a cookie, and then add the encrypted ticket to the cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); if (true == isCookiePersistent) { authCookie.Expires = authTicket.Expiration; } //Add the cookie to the outgoing cookies collection. context.Response.Cookies.Add(authCookie); }