Membership.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // System.Web.Security.Membership
  3. //
  4. // Authors:
  5. // Ben Maurer ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // (C) 2003 Ben Maurer
  9. // (C) 2005 Novell, inc.
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if NET_2_0
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.Text;
  35. namespace System.Web.Security
  36. {
  37. public abstract class Membership
  38. {
  39. private Membership ()
  40. {
  41. }
  42. public static MembershipUser CreateUser (string username, string password)
  43. {
  44. return CreateUser (username, password, null);
  45. }
  46. public static MembershipUser CreateUser (string username, string password, string email)
  47. {
  48. MembershipCreateStatus status;
  49. MembershipUser usr = CreateUser (username, password, email, null, null, true, out status);
  50. if (usr == null)
  51. throw new MembershipCreateUserException (status);
  52. return usr;
  53. }
  54. public static MembershipUser CreateUser (string username, string password, string email, string pwdQuestion, string pwdAnswer, bool isApproved, out MembershipCreateStatus status)
  55. {
  56. return Provider.CreateUser (username, password, email, pwdQuestion, pwdAnswer, isApproved, null, out status);
  57. }
  58. public static MembershipUser CreateUser (string username, string password, string email, string pwdQuestion, string pwdAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
  59. {
  60. return Provider.CreateUser (username, password, email, pwdQuestion, pwdAnswer, isApproved, providerUserKey, out status);
  61. }
  62. public static bool DeleteUser (string username)
  63. {
  64. return Provider.DeleteUser (username, true);
  65. }
  66. public static bool DeleteUser (string username, bool deleteAllRelatedData)
  67. {
  68. return Provider.DeleteUser (username, deleteAllRelatedData);
  69. }
  70. [MonoTODO]
  71. public static string GeneratePassword (int length, int numberOfNonAlphanumericCharacters)
  72. {
  73. throw new NotImplementedException ();
  74. }
  75. public static MembershipUserCollection GetAllUsers ()
  76. {
  77. int total;
  78. return GetAllUsers (1, int.MaxValue, out total);
  79. }
  80. public static MembershipUserCollection GetAllUsers (int pageIndex, int pageSize, out int totalRecords)
  81. {
  82. return Provider.GetAllUsers (pageIndex, pageSize, out totalRecords);
  83. }
  84. public static int GetNumberOfUsersOnline ()
  85. {
  86. return Provider.GetNumberOfUsersOnline ();
  87. }
  88. public static MembershipUser GetUser ()
  89. {
  90. return GetUser (HttpContext.Current.User.Identity.Name, true);
  91. }
  92. public static MembershipUser GetUser (bool userIsOnline)
  93. {
  94. return GetUser (HttpContext.Current.User.Identity.Name, userIsOnline);
  95. }
  96. public static MembershipUser GetUser (string username)
  97. {
  98. return GetUser (username, false);
  99. }
  100. public static MembershipUser GetUser (string username, bool userIsOnline)
  101. {
  102. return Provider.GetUser (username, userIsOnline);
  103. }
  104. public static MembershipUser GetUser (object providerUserKey)
  105. {
  106. return GetUser (providerUserKey, false);
  107. }
  108. public static MembershipUser GetUser (object providerUserKey, bool userIsOnline)
  109. {
  110. return Provider.GetUser (providerUserKey, userIsOnline);
  111. }
  112. public static string GetUserNameByEmail (string email)
  113. {
  114. return Provider.GetUserNameByEmail (email);
  115. }
  116. public static void UpdateUser (MembershipUser user)
  117. {
  118. Provider.UpdateUser (user);
  119. }
  120. public static bool ValidateUser (string username, string password)
  121. {
  122. return Provider.ValidateUser (username, password);
  123. }
  124. public static MembershipUserCollection FindUsersByEmail (string emailToMatch)
  125. {
  126. int totalRecords;
  127. return Provider.FindUsersByEmail (emailToMatch, 0, int.MaxValue, out totalRecords);
  128. }
  129. public static MembershipUserCollection FindUsersByEmail (string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
  130. {
  131. return Provider.FindUsersByEmail (emailToMatch, pageIndex, pageSize, out totalRecords);
  132. }
  133. public static MembershipUserCollection FindUsersByName (string nameToMatch)
  134. {
  135. int totalRecords;
  136. return Provider.FindUsersByName (nameToMatch, 0, int.MaxValue, out totalRecords);
  137. }
  138. public static MembershipUserCollection FindUsersByName (string nameToMatch, int pageIndex, int pageSize, out int totalRecords)
  139. {
  140. return Provider.FindUsersByName (nameToMatch, pageIndex, pageSize, out totalRecords);
  141. }
  142. public static string ApplicationName {
  143. get { return Provider.ApplicationName; }
  144. set { Provider.ApplicationName = value; }
  145. }
  146. public static bool EnablePasswordReset {
  147. get { return Provider.EnablePasswordReset; }
  148. }
  149. public static bool EnablePasswordRetrieval {
  150. get { return Provider.EnablePasswordRetrieval; }
  151. }
  152. public static bool RequiresQuestionAndAnswer {
  153. get { return Provider.RequiresQuestionAndAnswer; }
  154. }
  155. public static int MaxInvalidPasswordAttempts {
  156. get { return Provider.MaxInvalidPasswordAttempts; }
  157. }
  158. public static int MinRequiredNonAlphanumericCharacters {
  159. get { return Provider.MinRequiredNonAlphanumericCharacters; }
  160. }
  161. public static int MinRequiredPasswordLength {
  162. get { return Provider.MinRequiredPasswordLength; }
  163. }
  164. public static int PasswordAttemptWindow {
  165. get { return Provider.PasswordAttemptWindow; }
  166. }
  167. public static string PasswordStrengthRegularExpression {
  168. get { return Provider.PasswordStrengthRegularExpression; }
  169. }
  170. [MonoTODO]
  171. public static MembershipProvider Provider {
  172. get { throw new NotImplementedException (); }
  173. }
  174. [MonoTODO]
  175. public static MembershipProviderCollection Providers {
  176. get { throw new NotImplementedException (); }
  177. }
  178. [MonoTODO]
  179. public static int UserIsOnlineTimeWindow {
  180. get { throw new NotImplementedException (); }
  181. }
  182. public event MembershipValidatePasswordEventHandler ValidatingPassword {
  183. add { Provider.ValidatingPassword += value; }
  184. remove { Provider.ValidatingPassword -= value; }
  185. }
  186. }
  187. }
  188. #endif