1)所有功能,我需要在我的應用程序重寫
你主要是需要重寫的getUser和的ValidateUser爲了會員提供商使用登錄控制。其餘是可選的。
public class CustomMembershipProvider : MembershipProvider
{
public override MembershipUser GetUser(string username, bool userIsOnline)
{
throw new NotImplementedException();
}
public override bool ValidateUser(string username, string password)
{
throw new NotImplementedException();
}
}
2)所有的課程我需要繼承。到目前爲止,我使用了類: MemberShipProvider,RoleProvider。
MembershipProvider是必須的。如果您想按角色授權用戶,則需要實施RoleProvider。
3)ASP.NET可以自動連接到我的 數據庫的正確表。有沒有任何設置?像指定默認的 表名?
您重寫Membership Provider的原因是您希望使用您創建的自定義表格。你負責從數據庫返回數據;會員提供者不再需要知道表格的名稱。因此,答案是否定的 - 沒有設置。
4)有沒有任何Builtin函數可以將密碼設置爲Salted Hash? 或者我需要自己實現這個?
下面是成員資格提供用來生成散列密碼的方法 -
private static string GenerateSalt()
{
byte[] numArray = new byte[16];
(new RNGCryptoServiceProvider()).GetBytes(numArray);
string base64String = Convert.ToBase64String(numArray);
return base64String;
}
private string EncodePassword(string pass, int passwordFormat, string salt)
{
byte[] numArray;
byte[] numArray1;
string base64String;
bool length = passwordFormat != 0;
if (length)
{
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] numArray2 = Convert.FromBase64String(salt);
byte[] numArray3 = null;
HashAlgorithm hashAlgorithm = HashAlgorithm.Create(Membership.HashAlgorithmType);
if (hashAlgorithm as KeyedHashAlgorithm == null)
{
numArray1 = new byte[(int) numArray2.Length + (int) bytes.Length];
Buffer.BlockCopy(numArray2, 0, numArray1, 0, (int) numArray2.Length);
Buffer.BlockCopy(bytes, 0, numArray1, (int) numArray2.Length, (int) bytes.Length);
numArray3 = hashAlgorithm.ComputeHash(numArray1);
}
else
{
KeyedHashAlgorithm keyedHashAlgorithm = (KeyedHashAlgorithm) hashAlgorithm;
if (keyedHashAlgorithm.Key.Length != numArray2.Length)
{
if (keyedHashAlgorithm.Key.Length >= (int) numArray2.Length)
{
numArray = new byte[(int) keyedHashAlgorithm.Key.Length];
int num = 0;
while (true)
{
length = num < (int) numArray.Length;
if (!length)
{
break;
}
int num1 = Math.Min((int) numArray2.Length, (int) numArray.Length - num);
Buffer.BlockCopy(numArray2, 0, numArray, num, num1);
num = num + num1;
}
keyedHashAlgorithm.Key = numArray;
}
else
{
numArray = new byte[(int) keyedHashAlgorithm.Key.Length];
Buffer.BlockCopy(numArray2, 0, numArray, 0, (int) numArray.Length);
keyedHashAlgorithm.Key = numArray;
}
}
else
{
keyedHashAlgorithm.Key = numArray2;
}
numArray3 = keyedHashAlgorithm.ComputeHash(bytes);
}
base64String = Convert.ToBase64String(numArray3);
}
else
{
base64String = pass;
}
return base64String;
}
5)的WAT工具將有助於我依舊還是會在 功能受到限制,因爲我發現它可能對調試至少有幫助?
是的,你仍然可以使用網站管理工具,但它取決於你重寫的那些方法。
例如,如果您不覆蓋角色提供者,則將用戶分配給某個角色將不起作用。
http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider http://www.davidhayden.com/blog/dave/archive/2007/10/11/CreateCustomMembershipProviderASPNETWebsiteSecurity.aspx http://www.shiningstar.net/aspnet_articles/customprovider/CustomProvider.aspx http://www.devx.com/asp/Article/29256/0/page/3 http://www.15seconds.com/issue/050216.htm http://www.codeproject.com/KB/aspnet/CustomMembershipProviders.aspx http://www.codeproject.com/KB/aspnet/WSSecurityProvider.aspx
欣賞你必須回答我的問題很長的名單耐心。第4點對我來說是全新的。鏈接也很有幫助。 –