당신은 사용자 지정 공급자에 당신이 원하는 어떤 방법을 구현할 수 있으며, 귀하의 경우는 힘 메이크업 감각을 사용하기 전에 유형 그래서 그냥 캐스팅 회원 가입을 할 수 있습니다.
그러나 단순한 대역 외 정보를 얻기 위해 인터페이스를 중단하면 나중에 당신을 물어 듭니다. 이를 수행하고 공급자 API를 보존하고 향후 옵션을 계속 열 수있는 다른 방법이 있습니다.
과거에는 공급자로부터 소비자에게 대역 외 정보를 전달하기 위해 쿠키를 사용했습니다.
HttpContext.Current는 공급자와 동일하므로 공급자의 쿠키 집합을 소비자가 읽을 수 있습니다.
귀하의 제공자에게 전화 한 후 쿠키를 제거하십시오. 임시 쿠키를 만들면 실수를 최소화 할 수 있지만 컬렉션에서 제거하면됩니다.
다음은 작동하는 예제입니다.
CookieChannelMembershipProvider
using System;
using System.Web;
using System.Web.Security;
namespace CookieChannel
{
public class CookieChannelMembershipProvider : MembershipProvider
{
public override bool ValidateUser(string username, string password)
{
if(username=="asshat")
{
HttpContext.Current.Request.Cookies.Add(new HttpCookie("__cookiechannel", "user is an asshat. do not let him in."));
return false;
}
return true;
}
#region Not implemented
public override bool EnablePasswordRetrieval
{
get { throw new NotImplementedException(); }
}
public override bool EnablePasswordReset
{
get { throw new NotImplementedException(); }
}
public override bool RequiresQuestionAndAnswer
{
get { throw new NotImplementedException(); }
}
public override string ApplicationName
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public override int MaxInvalidPasswordAttempts
{
get { throw new NotImplementedException(); }
}
public override int PasswordAttemptWindow
{
get { throw new NotImplementedException(); }
}
public override bool RequiresUniqueEmail
{
get { throw new NotImplementedException(); }
}
public override MembershipPasswordFormat PasswordFormat
{
get { throw new NotImplementedException(); }
}
public override int MinRequiredPasswordLength
{
get { throw new NotImplementedException(); }
}
public override int MinRequiredNonAlphanumericCharacters
{
get { throw new NotImplementedException(); }
}
public override string PasswordStrengthRegularExpression
{
get { throw new NotImplementedException(); }
}
public override MembershipUser CreateUser(string username, string password, string email,
string passwordQuestion, string passwordAnswer, bool isApproved,
object providerUserKey, out MembershipCreateStatus status)
{
throw new NotImplementedException();
}
public override bool ChangePasswordQuestionAndAnswer(string username, string password,
string newPasswordQuestion, string newPasswordAnswer)
{
throw new NotImplementedException();
}
public override string GetPassword(string username, string answer)
{
throw new NotImplementedException();
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new NotImplementedException();
}
public override string ResetPassword(string username, string answer)
{
throw new NotImplementedException();
}
public override void UpdateUser(MembershipUser user)
{
throw new NotImplementedException();
}
public override bool UnlockUser(string userName)
{
throw new NotImplementedException();
}
public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
{
throw new NotImplementedException();
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
throw new NotImplementedException();
}
public override string GetUserNameByEmail(string email)
{
throw new NotImplementedException();
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new NotImplementedException();
}
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
throw new NotImplementedException();
}
public override int GetNumberOfUsersOnline()
{
throw new NotImplementedException();
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize,
out int totalRecords)
{
throw new NotImplementedException();
}
public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize,
out int totalRecords)
{
throw new NotImplementedException();
}
#endregion
}
}
의 Web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<authentication mode="Windows" />
<membership defaultProvider="cookieChannelProvider" userIsOnlineTimeWindow="15">
<providers>
<add
name="cookieChannelProvider"
type="CookieChannel.CookieChannelMembershipProvider, CookieChannel"
connectionStringName="none"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
/>
</providers>
</membership>
</system.web>
</configuration>
기본.영문
<%@ Page Language="C#" %>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
ValidateUser("user", "user");
}
protected void Button2_Click(object sender, EventArgs e)
{
ValidateUser("asshat", "asshat");
}
private void ValidateUser(string username, string password)
{
bool validated = Membership.ValidateUser(username, password);
string message = validated.ToString();
if (Request.Cookies["__cookiechannel"] != null)
{
message += ":" + Request.Cookies["__cookiechannel"].Value;
Request.Cookies.Remove("__cookiechannel");
}
Label1.Text = message;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Validate Valued User" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Validate Asshat User" />
</div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
그것은, 알 무력 암호 공격을 시도하는 사람이 중지에 수행하고 잠재적으로 올바른 암호를 제시하기보다는 기다리는 웹 기반 응용 프로그램에 대한 잠금 아웃을보고 좋은 생각이 아니다 잠긴 계정이므로 액세스 할 수 없습니다. 너를위한 생각. – Lazarus
힌트 나사로를 주셔서 감사합니다. – Cosmo
이것은 MembershipProvider의 부족한 부분입니다. ValidateUser()는 bool 만 반환하고 BAD 옵션을 남깁니다. 1) 추가 정보 (오버 헤드)에 대한 DB 쿼리, 2) 메서드 추가 및 공급자 독립 (독립 깨뜨림) 또는 3) 대역 외 쿠키 작업. MS가 공급자를 업데이트해야합니다. ValidateUser가 최소한 반환되면 CreateUser()가 MembershipCreateStatus 열거 형을 반환하는 것처럼 AuthenticationStatuts를 열거다면 멋질 것입니다. MemberhipCreateStatus enum조차도 제한되어 있으므로 (http://forums.asp.net/t/1521981.aspx) 조금 더보고 싶습니다. – EBarr