Guest User

Untitled

a guest
Feb 13th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <configuration>
  3. <system.web>
  4. <authentication mode="Forms">
  5. <forms name="DataViewer" loginUrl="login.aspx">
  6. <credentials passwordFormat="Clear">
  7. <user name="devuser" password="test" />
  8. </credentials>
  9. </forms>
  10. </authentication>
  11. <authorization>
  12. <deny users="?" />
  13. </authorization>
  14. </system.web>
  15.  
  16. <asp:Login ID="login" runat="server" />
  17.  
  18. public class WebConfigMembershipProvider : MembershipProvider
  19. {
  20. private FormsAuthenticationUserCollection _users = null;
  21. private FormsAuthPasswordFormat _passwordFormat;
  22.  
  23. public override void Initialize(string name,
  24. System.Collections.Specialized.NameValueCollection config)
  25. {
  26. base.Initialize(name, config);
  27. _passwordFormat = getPasswordFormat();
  28. }
  29.  
  30. public override bool ValidateUser(string username, string password)
  31. {
  32. var user = getUsers()[username];
  33. if (user == null) return false;
  34.  
  35. if (_passwordFormat == FormsAuthPasswordFormat.Clear)
  36. {
  37. if (user.Password == password)
  38. {
  39. return true;
  40. }
  41. }
  42. else
  43. {
  44. if (user.Password == FormsAuthentication.HashPasswordForStoringInConfigFile(password,
  45. _passwordFormat.ToString()))
  46. {
  47. return true;
  48. }
  49. }
  50.  
  51. return false;
  52. }
  53.  
  54. protected FormsAuthenticationUserCollection getUsers()
  55. {
  56. if (_users == null)
  57. {
  58. AuthenticationSection section = getAuthenticationSection();
  59. FormsAuthenticationCredentials creds = section.Forms.Credentials;
  60. _users = section.Forms.Credentials.Users;
  61. }
  62. return _users;
  63. }
  64.  
  65. protected AuthenticationSection getAuthenticationSection()
  66. {
  67. Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
  68. return (AuthenticationSection)config.GetSection("system.web/authentication");
  69. }
  70.  
  71. protected FormsAuthPasswordFormat getPasswordFormat()
  72. {
  73. return getAuthenticationSection().Forms.Credentials.PasswordFormat;
  74. }
  75.  
  76. <membership>
  77. <providers>
  78. <remove name="AspNetSqlMembershipProvider"/>
  79. </providers>
  80. </membership>
Add Comment
Please, Sign In to add comment