PageRenderTime 33ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/mcs/class/referencesource/System.Web/Configuration/MembershipSection.cs

https://github.com/directhex/mono-1
C# | 163 lines | 88 code | 12 blank | 63 comment | 0 complexity | 401811d195cf4742da74659903d8b714 MD5 | raw file
  1. //------------------------------------------------------------------------------
  2. // <copyright file="MembershipSection.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. //------------------------------------------------------------------------------
  6. namespace System.Web.Configuration {
  7. using System;
  8. using System.Xml;
  9. using System.Configuration;
  10. using System.Collections.Specialized;
  11. using System.Collections;
  12. using System.Globalization;
  13. using System.IO;
  14. using System.Text;
  15. using System.ComponentModel;
  16. using System.Security.Permissions;
  17. /* <!-- membership config:
  18. Attributes:
  19. defaultProvider="string" Name of provider to use by default
  20. userIsOnlineTimeWindow="int" Time window (in minutes) to consider a User as being Online after since last activity
  21. hashAlgorithmType="[SHA1|SHA512|MD5|...]" Any valid hash algorithm supported by .NET framework, default is SHA1
  22. Child nodes:
  23. <providers> Providers (class must inherit from MembershipProvider)
  24. <add Add a provider
  25. name="string" Name to identify this provider instance by
  26. type="string" Class that implements MembershipProvider
  27. provider-specific-configuration />
  28. <remove Remove a provider
  29. name="string" /> Name of provider to remove
  30. <clear/> Remove all providers
  31. </providers>
  32. Configuration for SqlMembershipProvider and AccessMembershipProvider:
  33. connectionStringName="string" Name corresponding to the entry in <connectionStrings> section where the connection string for the provider is specified
  34. maxInvalidPasswordAttempts="int" A user's account is locked out when the number of failed password answer attempts matches the value of the configuration setting
  35. passwordAttemptWindow="int" The time window, in minutes, during which failed password attempts and failed password answer attempts are tracked
  36. enablePasswordRetrieval="[true|false]" Should the provider support password retrievals
  37. enablePasswordReset="[true|false]" Should the provider support password resets
  38. requiresQuestionAndAnswer="[true|false]" Should the provider require Q & A, the default is true
  39. applicationName="string" Optional string to identity the application: defaults to Application Metabase path
  40. requiresUniqueEmail="[true|false]" Should the provider require a unique email to be specified
  41. passwordFormat="[Clear|Hashed|Encrypted]" Storage format for the password: Hashed (SHA1), Clear or Encrypted (Triple-DES)
  42. description="string" Description of what the provider does
  43. commandTimeout="int" Command timeout value for SQL command
  44. minRequiredPasswordLength="int" The minimum number of characters required in a password
  45. minRequiredNonAlphanumericCharacters="int" The minimum number of non-alphanumeric characters that are required in a password
  46. passwordStrengthRegularExpression="string" The regular expression used to test the password strength
  47. passwordStrengthRegexTimeout="int" The timeout in milliseconds for the regex we use to check password strength
  48. -->
  49. <membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="15" >
  50. <providers>
  51. <add name="AspNetSqlMembershipProvider"
  52. type="System.Web.Security.SqlMembershipProvider, System.Web, Version=%ASSEMBLY_VERSION%, Culture=neutral, PublicKeyToken=%MICROSOFT_PUBLICKEY%"
  53. connectionStringName="LocalSqlServer"
  54. maxInvalidPasswordAttempts="5"
  55. passwordAttemptWindow="10"
  56. minRequiredPasswordLength="7"
  57. minRequireNonAlphanumericCharacters="1"
  58. passwordStrengthRegularExpression=""
  59. passwordStrengthRegexTimeout="2000"
  60. enablePasswordRetrieval="false"
  61. enablePasswordReset="true"
  62. requiresQuestionAndAnswer="true"
  63. applicationName="/"
  64. requiresUniqueEmail="false"
  65. passwordFormat="Hashed"
  66. description="Stores and retrieves membership data from the local Microsoft SQL Server database"
  67. />
  68. </providers>
  69. </membership>
  70. */
  71. public sealed class MembershipSection : ConfigurationSection {
  72. private static ConfigurationPropertyCollection _properties;
  73. private static readonly ConfigurationProperty _propProviders;
  74. private static readonly ConfigurationProperty _propDefaultProvider;
  75. private static readonly ConfigurationProperty _propUserIsOnlineTimeWindow;
  76. private static readonly ConfigurationProperty _propHashAlgorithmType;
  77. static MembershipSection() {
  78. // Property initialization
  79. _propProviders = new ConfigurationProperty("providers", typeof(ProviderSettingsCollection), null, ConfigurationPropertyOptions.None);
  80. _propDefaultProvider =
  81. new ConfigurationProperty("defaultProvider",
  82. typeof(string),
  83. "AspNetSqlMembershipProvider",
  84. null,
  85. StdValidatorsAndConverters.NonEmptyStringValidator,
  86. ConfigurationPropertyOptions.None);
  87. _propUserIsOnlineTimeWindow =
  88. new ConfigurationProperty("userIsOnlineTimeWindow",
  89. typeof(TimeSpan),
  90. TimeSpan.FromMinutes(15.0),
  91. StdValidatorsAndConverters.TimeSpanMinutesConverter,
  92. new TimeSpanValidator(TimeSpan.FromMinutes(1), TimeSpan.MaxValue),
  93. ConfigurationPropertyOptions.None);
  94. _propHashAlgorithmType = new ConfigurationProperty("hashAlgorithmType", typeof(string), string.Empty, ConfigurationPropertyOptions.None);
  95. _properties = new ConfigurationPropertyCollection();
  96. _properties.Add(_propProviders);
  97. _properties.Add(_propDefaultProvider);
  98. _properties.Add(_propUserIsOnlineTimeWindow);
  99. _properties.Add(_propHashAlgorithmType);
  100. }
  101. public MembershipSection() {
  102. }
  103. protected override ConfigurationPropertyCollection Properties {
  104. get {
  105. return _properties;
  106. }
  107. }
  108. [ConfigurationProperty("providers")]
  109. public ProviderSettingsCollection Providers {
  110. get {
  111. return (ProviderSettingsCollection)base[_propProviders];
  112. }
  113. }
  114. [ConfigurationProperty("defaultProvider", DefaultValue = "AspNetSqlMembershipProvider")]
  115. [StringValidator(MinLength = 1)]
  116. public string DefaultProvider {
  117. get {
  118. return (string)base[_propDefaultProvider];
  119. }
  120. set {
  121. base[_propDefaultProvider] = value;
  122. }
  123. }
  124. [ConfigurationProperty("hashAlgorithmType", DefaultValue = "")]
  125. public string HashAlgorithmType {
  126. get {
  127. return (string)base[_propHashAlgorithmType];
  128. }
  129. set {
  130. base[_propHashAlgorithmType] = value;
  131. }
  132. }
  133. internal void ThrowHashAlgorithmException() {
  134. throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_hash_algorithm_type, HashAlgorithmType), ElementInformation.Properties["hashAlgorithmType"].Source, ElementInformation.Properties["hashAlgorithmType"].LineNumber);
  135. }
  136. [ConfigurationProperty("userIsOnlineTimeWindow", DefaultValue = "00:15:00")]
  137. [TypeConverter(typeof(TimeSpanMinutesConverter))]
  138. [TimeSpanValidator(MinValueString = "00:01:00", MaxValueString = TimeSpanValidatorAttribute.TimeSpanMaxValue)]
  139. public TimeSpan UserIsOnlineTimeWindow {
  140. get {
  141. return (TimeSpan)base[_propUserIsOnlineTimeWindow];
  142. }
  143. set {
  144. base[_propUserIsOnlineTimeWindow] = value;
  145. }
  146. }
  147. } // class MembershipSection
  148. }