Custom MembershipProvider
Following are the steps to configure your Windows predefined User Access mecanisum . following are the screen shots and steps how to configure SqlMembershipProvider with different data base instade of the Aspnet.mdb Sata Base
Step 0 Configure your data base with aspnet_regsql
Step 1 Create Class
This class will help to create our own member ship configuration with database.
The overridable method CreateUser will help to create new user in the data base
public class NGOSqlMembershipProvider : SqlMembershipProvider
{
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
if (username.ToLower() == password.ToLower())
{
status = MembershipCreateStatus.InvalidPassword;
return null;
}
else
{
return base.CreateUser(username, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status);
}
}
}
Setp 2 add machine key and algorithm which will use for generating the encryption in of our password
<machineKey validationKey="287C5D125D6B7E7223E1F719E3D58D17BB967703017E1BBE28618FAC6C4501E910C7E59800B5D4C2EDD5B0ED98874A3E952D60BAF260D9D374A74C76CB741803" decryptionKey="5C1D8BD9DF3E1B4E1D01132F234266616E0D5EF772FE80AB" validation="SHA1"/>
Step 3 Create connection string in web.config file this connection string we are going to pass to custom SqlProvider
<connectionStrings>
<add name="NgopediaConnection" connectionString="Data Source=SHREYAS-PC;Initial Catalog=DEMOTEST ;User ID=sa;Password=t#d98^55;"/>
<add name="NewConnectionstring" providerName="AspNetSqlProvider"
connectionStrings>
Step 4 Now the most important thing to update the configuration setting in the config file. Using this configuration setting login controls can access data
Note:- The type key word is very important in this we need to specify the class which is inherited by SqlMembershipProvider Class with fully qualified name should be there.
<add name="NgoNetSqlProvider"
connectionStringName="NgopediaConnection"
applicationName="/"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="true"
requiresUniqueEmail="true"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="5"
passwordAttemptWindow="10"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
type="NGOPEDIA.NGOSqlMembershipProvider"/>
and Your ready with your Custom MemberShip provider