PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Interfaces/IAuthenticator.cs

http://owasp-esapi-classicasp.googlecode.com/
C# | 197 lines | 25 code | 16 blank | 156 comment | 0 complexity | 85b790607ece8b61eda8682198547e85 MD5 | raw file
  1. /// <summary> OWASP Enterprise Security API .NET (ESAPI.NET)
  2. ///
  3. /// This file is part of the Open Web Application Security Project (OWASP)
  4. /// Enterprise Security API (ESAPI) project. For details, please see
  5. /// http://www.owasp.org/esapi.
  6. ///
  7. /// Copyright (c) 2008 - The OWASP Foundation
  8. ///
  9. /// The ESAPI is published by OWASP under the LGPL. You should read and accept the
  10. /// LICENSE before you use, modify, and/or redistribute this software.
  11. ///
  12. /// </summary>
  13. /// <author> Alex Smolen <a href="http://www.foundstone.com">Foundstone</a>
  14. /// </author>
  15. /// <created> 2008 </created>
  16. using System;
  17. using System.Collections;
  18. using HttpInterfaces;
  19. using System.Runtime.InteropServices;
  20. namespace Owasp.Esapi.Interfaces
  21. {
  22. /// <summary> The IAuthenticator interface defines a set of methods for generating and
  23. /// handling account credentials and session identifiers. The goal of this
  24. /// interface is to encourage developers to protect credentials from disclosure
  25. /// to the maximum extent possible.
  26. ///
  27. /// Once possible implementation relies on the use of a thread local variable to
  28. /// store the current user's identity. The application is responsible for calling
  29. /// SetCurrentUser() as soon as possible after each HTTP request is received. The
  30. /// value of GetCurrentUser() is used in several other places in this API. This
  31. /// eliminates the need to pass a user object to methods throughout the library.
  32. /// For example, all of the logging, access control, and exception calls need
  33. /// access to the currently logged in user.
  34. ///
  35. /// The goal is to minimize the responsibility of the developer for
  36. /// authentication. In this example, the user simply calls authenticate with the
  37. /// current request and the name of the parameters containing the username and
  38. /// password. The implementation should verify the password if necessary, create
  39. /// a session if necessary, and set the user as the current user.
  40. ///
  41. /// try {
  42. /// Esapi.Authenticator().Authenticate(request, response, username, password);
  43. /// // continue with authenticated user
  44. /// } catch (AuthenticationException e) {
  45. /// // handle failed authentication (it's already been logged)
  46. /// }
  47. ///
  48. ///
  49. /// </summary>
  50. /// <author> Alex Smolen (alex.smolen@foundstone.com)
  51. /// </author>
  52. /// <since> February 20, 2008
  53. /// </since>
  54. [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
  55. public interface IAuthenticator
  56. {
  57. /// <summary> Gets all the user names.
  58. ///
  59. /// </summary>
  60. /// <returns> The user names, as a list.
  61. /// </returns>
  62. IList GetUserNames();
  63. /// <summary> Authenticates the user's credentials from the HttpRequest if
  64. /// necessary, creates a session if necessary, and sets the user as the
  65. /// current user.
  66. /// </summary>
  67. /// <returns> The User object, if the login attempt was successful.
  68. /// </returns>
  69. IUser Login();
  70. /// <summary> Creates a user.
  71. ///
  72. /// </summary>
  73. /// <param name="accountName">The account name for the user.
  74. /// </param>
  75. /// <param name="password1">The password for the user.
  76. /// </param>
  77. /// <param name="password2">A confirmation of the password for the user.
  78. ///
  79. /// </param>
  80. /// <returns> The new User object.
  81. ///
  82. /// </returns>
  83. IUser CreateUser(string accountName, string password1, string password2);
  84. /// <summary> Generates a cryptographically strong password.
  85. ///
  86. /// </summary>
  87. /// <returns>The cryptographically strong password.
  88. /// </returns>
  89. string GenerateStrongPassword();
  90. /// <summary> Generates a strong password, different fromt the previous password.
  91. ///
  92. /// </summary>
  93. /// <param name="oldPassword">The old password for the user.
  94. /// </param>
  95. /// <param name="user">The user to set the password for.
  96. ///
  97. /// </param>
  98. /// <returns> The cryptographically strong password.
  99. /// </returns>
  100. string GenerateStrongPassword(string oldPassword, IUser user);
  101. /// <summary> Returns the User matching the provided accountName.
  102. ///
  103. /// </summary>
  104. /// <param name="accountName">The account name to match.
  105. ///
  106. /// </param>
  107. /// <returns> The matching User object, or null if no match exists.
  108. /// </returns>
  109. IUser GetUser(string accountName);
  110. /// <summary> Returns the currently logged in User.
  111. ///
  112. /// </summary>
  113. /// <returns> The matching User object, or the Anonymous user if no match
  114. /// exists.
  115. /// </returns>
  116. IUser GetCurrentUser();
  117. /// <summary> Sets the currently logged in User.
  118. ///
  119. /// </summary>
  120. /// <param name="user">The current user.
  121. /// </param>
  122. void SetCurrentUser(IUser user);
  123. /// <summary> Returns a string representation of the hashed password, using the
  124. /// accountName as the salt. The salt helps to prevent against "rainbow"
  125. /// table attacks where the attacker pre-calculates hashes for known strings.
  126. ///
  127. /// </summary>
  128. /// <param name="password">The password.
  129. /// </param>
  130. /// <param name="accountName">The account name.
  131. ///
  132. /// </param>
  133. /// <returns> The hashed password.
  134. /// </returns>
  135. string HashPassword(string password, string accountName);
  136. /// <summary> Removes the account for the list of available account.
  137. ///
  138. /// </summary>
  139. /// <param name="accountName">The account name for the account to remove.
  140. ///
  141. /// </param>
  142. void RemoveUser(string accountName);
  143. /// <summary> Validates the strength of the account name.
  144. ///
  145. /// </summary>
  146. /// <param name="accountName">The account name to validate the strength of.
  147. ///
  148. /// </param>
  149. /// <returns> true, if the account name has sufficient strength.
  150. ///
  151. /// </returns>
  152. void VerifyAccountNameStrength(string accountName);
  153. /// <summary> Validates the strength of the password.
  154. ///
  155. /// </summary>
  156. /// <param name="oldPassword">The old password.
  157. /// </param>
  158. /// <param name="newPassword">The new password.
  159. ///
  160. /// </param>
  161. /// <returns> true, if the password has sufficient strength.
  162. ///
  163. /// </returns>
  164. void VerifyPasswordStrength(string oldPassword, string newPassword);
  165. /// <summary> Verifies the account exists.
  166. ///
  167. /// </summary>
  168. /// <param name="accountName">The account name to check.
  169. ///
  170. /// </param>
  171. /// <returns> true, if the account exists.
  172. /// </returns>
  173. bool Exists(string accountName);
  174. /// <summary>
  175. /// Gets the user from the current session.
  176. /// </summary>
  177. /// <param name="request">The current HTTP request.</param>
  178. /// <returns>The current user.</returns>
  179. IUser GetUserFromSession(IHttpRequest request);
  180. }
  181. }