Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0"?>
- <configuration>
- <system.web>
- <authentication mode="Forms">
- <forms name="DataViewer" loginUrl="login.aspx">
- <credentials passwordFormat="Clear">
- <user name="devuser" password="test" />
- </credentials>
- </forms>
- </authentication>
- <authorization>
- <deny users="?" />
- </authorization>
- </system.web>
- <asp:Login ID="login" runat="server" />
- public class WebConfigMembershipProvider : MembershipProvider
- {
- private FormsAuthenticationUserCollection _users = null;
- private FormsAuthPasswordFormat _passwordFormat;
- public override void Initialize(string name,
- System.Collections.Specialized.NameValueCollection config)
- {
- base.Initialize(name, config);
- _passwordFormat = getPasswordFormat();
- }
- public override bool ValidateUser(string username, string password)
- {
- var user = getUsers()[username];
- if (user == null) return false;
- if (_passwordFormat == FormsAuthPasswordFormat.Clear)
- {
- if (user.Password == password)
- {
- return true;
- }
- }
- else
- {
- if (user.Password == FormsAuthentication.HashPasswordForStoringInConfigFile(password,
- _passwordFormat.ToString()))
- {
- return true;
- }
- }
- return false;
- }
- protected FormsAuthenticationUserCollection getUsers()
- {
- if (_users == null)
- {
- AuthenticationSection section = getAuthenticationSection();
- FormsAuthenticationCredentials creds = section.Forms.Credentials;
- _users = section.Forms.Credentials.Users;
- }
- return _users;
- }
- protected AuthenticationSection getAuthenticationSection()
- {
- Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
- return (AuthenticationSection)config.GetSection("system.web/authentication");
- }
- protected FormsAuthPasswordFormat getPasswordFormat()
- {
- return getAuthenticationSection().Forms.Credentials.PasswordFormat;
- }
- <membership>
- <providers>
- <remove name="AspNetSqlMembershipProvider"/>
- </providers>
- </membership>
Add Comment
Please, Sign In to add comment