You can absolutely use System.Web.Security
within a console or winforms app.
Here's a simple console application:
static void Main(string[] args)
{
MembershipProvider provider = Membership.Provider;
MembershipUser myUser = provider.GetUser("myUser", false);
if( myUser != null ) provider.DeleteUser("myUser", true);
MembershipCreateStatus status;
myUser = provider.CreateUser("myUser", "password", "[email protected]", null, null, true, null, out status);
if (status != MembershipCreateStatus.Success)
{
Console.WriteLine("Could not create user. Reason: " + status.ToString());
Console.ReadLine();
return;
}
Console.WriteLine("Authenticating with \"password\": " + provider.ValidateUser("myUser", "password").ToString());
string newPassword = myUser.ResetPassword();
Console.WriteLine("Authenticating with \"password\": " + provider.ValidateUser("myUser", "password").ToString());
Console.WriteLine("Authenticating with new password: " + provider.ValidateUser("myUser", newPassword).ToString());
Console.ReadLine();
}
And the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear />
<add name="MyMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyConnectionString"
applicationName="MyApplication"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
requiresQuestionAndAnswer="false" />
</providers>
</membership>
</system.web>
</configuration>