Advertisement
Guest User

Untitled

a guest
Jun 30th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 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. using System.Configuration;
  19. using System.Web.Configuration;
  20. using System.Web.Security;
  21.  
  22. public class WebConfigMembershipProvider : MembershipProvider
  23. {
  24. private FormsAuthenticationUserCollection _users = null;
  25. private FormsAuthPasswordFormat _passwordFormat;
  26.  
  27. public override void Initialize(string name,
  28. System.Collections.Specialized.NameValueCollection config)
  29. {
  30. base.Initialize(name, config);
  31. _passwordFormat = getPasswordFormat();
  32. }
  33.  
  34. public override bool ValidateUser(string username, string password)
  35. {
  36. var user = getUsers()[username];
  37. if (user == null) return false;
  38.  
  39. if (_passwordFormat == FormsAuthPasswordFormat.Clear)
  40. {
  41. if (user.Password == password)
  42. {
  43. return true;
  44. }
  45. }
  46. else
  47. {
  48. if (user.Password == FormsAuthentication.HashPasswordForStoringInConfigFile(password,
  49. _passwordFormat.ToString()))
  50. {
  51. return true;
  52. }
  53. }
  54.  
  55. return false;
  56. }
  57.  
  58. protected FormsAuthenticationUserCollection getUsers()
  59. {
  60. if (_users == null)
  61. {
  62. AuthenticationSection section = getAuthenticationSection();
  63. FormsAuthenticationCredentials creds = section.Forms.Credentials;
  64. _users = section.Forms.Credentials.Users;
  65. }
  66. return _users;
  67. }
  68.  
  69. protected AuthenticationSection getAuthenticationSection()
  70. {
  71. Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
  72. return (AuthenticationSection)config.GetSection("system.web/authentication");
  73. }
  74.  
  75. protected FormsAuthPasswordFormat getPasswordFormat()
  76. {
  77. return getAuthenticationSection().Forms.Credentials.PasswordFormat;
  78. }
  79. }
  80.  
  81. <membership>
  82. <providers>
  83. <remove name="AspNetSqlMembershipProvider"/>
  84. </providers>
  85. </membership>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement