Custom Membership Provider

G

Guest

Hi,
I have created a custom membership provider that i use to create certain
types of user accounts that
only require a User Name and Password nothing else this code below works
great if i use the CreateUserWizard.

But if i try and create the account on my own in code behind i keep getting
a status back of.
"InvalidAnswer" how can i properly handle this status and correct for it.

What needs to be done to make this work correctly.


Code and Web.config below.

<add name="FiPort_MembershipProviderEx"
connectionStringName="LocalSqlServer"
applicationName="/"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="3"
passwordAttemptWindow="10"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
type="SK.FiPort.DAL.SqlClient.SqlMembershipProviderEx, __code"/>


class SqlMembershipProviderEx : 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);

}


}

}


protected void btnCreate_Click(object sender, EventArgs e)
{
MembershipProvider mp =
Membership.Providers["FiPort_MembershipProviderEx"];

MembershipCreateStatus status;

mp.CreateUser(this.txtServiceProviderID.Text, this.txtPassword.Text,
String.Empty,
String.Empty, String.Empty, true, null, out status);

}
 
G

Guest

Hi,
Peter thanks for responding to my question.
What you see is how i have been using the class.
When the CreateUserWizered fires its CeratedUser Event my class gets called
and the user is created.

What i am trying to do is gain more control of the creation of the account.
By creating my own form with a button click event that i can control.
Such as validation and other things that i need to happen.

I have tried the following with my provider but still get the same result.

I added these to the class. hoping this would solve it but it gives back a
status
of "InvalidAnswer"

Thanks,
Ron

public override bool ChangePasswordQuestionAndAnswer(string username, string
password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new NotSupportedException();
}

public override string ResetPassword(string username, string answer)
{
throw new NotSupportedException();
}

public override bool EnablePasswordReset
{
get { return base.EnablePasswordReset;}
}

public override bool EnablePasswordRetrieval
{
get{return base.EnablePasswordRetrieval; }
}

public override bool RequiresQuestionAndAnswer
{
get{return base.RequiresQuestionAndAnswer;}
}

public override bool RequiresUniqueEmail
{
get{return base.RequiresUniqueEmail;}
}






Peter Bromberg said:
Ron,
I don't know what your derived MembershipProvider class looks like, but the
bottom line is you are deriving from an abstract base class. So you need to
handle the RequiresQuestion etc. properties to return false by default if
that's the way you want your class to behave.
This link may help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt1.asp

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Ron said:
Hi,
I have created a custom membership provider that i use to create certain
types of user accounts that
only require a User Name and Password nothing else this code below works
great if i use the CreateUserWizard.

But if i try and create the account on my own in code behind i keep getting
a status back of.
"InvalidAnswer" how can i properly handle this status and correct for it.

What needs to be done to make this work correctly.


Code and Web.config below.

<add name="FiPort_MembershipProviderEx"
connectionStringName="LocalSqlServer"
applicationName="/"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="3"
passwordAttemptWindow="10"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
type="SK.FiPort.DAL.SqlClient.SqlMembershipProviderEx, __code"/>


class SqlMembershipProviderEx : 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);

}


}

}


protected void btnCreate_Click(object sender, EventArgs e)
{
MembershipProvider mp =
Membership.Providers["FiPort_MembershipProviderEx"];

MembershipCreateStatus status;

mp.CreateUser(this.txtServiceProviderID.Text, this.txtPassword.Text,
String.Empty,
String.Empty, String.Empty, true, null, out status);

}
 
G

Guest

Ron,
Example: "I don't care what the base class does, I want my class to NOT
require password question / answer.":

public override bool RequiresQuestionAndAnswer
{
get{ return false;}
}


Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Ron said:
Hi,
Peter thanks for responding to my question.
What you see is how i have been using the class.
When the CreateUserWizered fires its CeratedUser Event my class gets called
and the user is created.

What i am trying to do is gain more control of the creation of the account.
By creating my own form with a button click event that i can control.
Such as validation and other things that i need to happen.

I have tried the following with my provider but still get the same result.

I added these to the class. hoping this would solve it but it gives back a
status
of "InvalidAnswer"

Thanks,
Ron

public override bool ChangePasswordQuestionAndAnswer(string username, string
password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new NotSupportedException();
}

public override string ResetPassword(string username, string answer)
{
throw new NotSupportedException();
}

public override bool EnablePasswordReset
{
get { return base.EnablePasswordReset;}
}

public override bool EnablePasswordRetrieval
{
get{return base.EnablePasswordRetrieval; }
}

public override bool RequiresQuestionAndAnswer
{
get{return base.RequiresQuestionAndAnswer;}
}

public override bool RequiresUniqueEmail
{
get{return base.RequiresUniqueEmail;}
}






Peter Bromberg said:
Ron,
I don't know what your derived MembershipProvider class looks like, but the
bottom line is you are deriving from an abstract base class. So you need to
handle the RequiresQuestion etc. properties to return false by default if
that's the way you want your class to behave.
This link may help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt1.asp

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Ron said:
Hi,
I have created a custom membership provider that i use to create certain
types of user accounts that
only require a User Name and Password nothing else this code below works
great if i use the CreateUserWizard.

But if i try and create the account on my own in code behind i keep getting
a status back of.
"InvalidAnswer" how can i properly handle this status and correct for it.

What needs to be done to make this work correctly.


Code and Web.config below.

<add name="FiPort_MembershipProviderEx"
connectionStringName="LocalSqlServer"
applicationName="/"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="3"
passwordAttemptWindow="10"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
type="SK.FiPort.DAL.SqlClient.SqlMembershipProviderEx, __code"/>


class SqlMembershipProviderEx : 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);

}


}

}


protected void btnCreate_Click(object sender, EventArgs e)
{
MembershipProvider mp =
Membership.Providers["FiPort_MembershipProviderEx"];

MembershipCreateStatus status;

mp.CreateUser(this.txtServiceProviderID.Text, this.txtPassword.Text,
String.Empty,
String.Empty, String.Empty, true, null, out status);

}
 
G

Guest

Peter,
Thanks for the link after going thorugh the documnetation agian and
reviewing some chapters in some books. I was able to get it work just as you
posted here.

It seems strange that the documentaion dose not mention that what is in the
web.config dose not matter and that you to have expectitly inform the
provider that the value is false.

Am i safe to assume that my passwords are Encrypted as specifed in the web
config or do i need handle this as well?

You would think that it would use the settings form the config and just do
its job.

Thanks agian for the help.
Ron


Peter Bromberg said:
Ron,
Example: "I don't care what the base class does, I want my class to NOT
require password question / answer.":

public override bool RequiresQuestionAndAnswer
{
get{ return false;}
}


Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Ron said:
Hi,
Peter thanks for responding to my question.
What you see is how i have been using the class.
When the CreateUserWizered fires its CeratedUser Event my class gets called
and the user is created.

What i am trying to do is gain more control of the creation of the account.
By creating my own form with a button click event that i can control.
Such as validation and other things that i need to happen.

I have tried the following with my provider but still get the same result.

I added these to the class. hoping this would solve it but it gives back a
status
of "InvalidAnswer"

Thanks,
Ron

public override bool ChangePasswordQuestionAndAnswer(string username, string
password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new NotSupportedException();
}

public override string ResetPassword(string username, string answer)
{
throw new NotSupportedException();
}

public override bool EnablePasswordReset
{
get { return base.EnablePasswordReset;}
}

public override bool EnablePasswordRetrieval
{
get{return base.EnablePasswordRetrieval; }
}

public override bool RequiresQuestionAndAnswer
{
get{return base.RequiresQuestionAndAnswer;}
}

public override bool RequiresUniqueEmail
{
get{return base.RequiresUniqueEmail;}
}






Peter Bromberg said:
Ron,
I don't know what your derived MembershipProvider class looks like, but the
bottom line is you are deriving from an abstract base class. So you need to
handle the RequiresQuestion etc. properties to return false by default if
that's the way you want your class to behave.
This link may help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Prt1.asp

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




:

Hi,
I have created a custom membership provider that i use to create certain
types of user accounts that
only require a User Name and Password nothing else this code below works
great if i use the CreateUserWizard.

But if i try and create the account on my own in code behind i keep getting
a status back of.
"InvalidAnswer" how can i properly handle this status and correct for it.

What needs to be done to make this work correctly.


Code and Web.config below.

<add name="FiPort_MembershipProviderEx"
connectionStringName="LocalSqlServer"
applicationName="/"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
maxInvalidPasswordAttempts="3"
passwordAttemptWindow="10"
minRequiredPasswordLength="8"
minRequiredNonalphanumericCharacters="0"
type="SK.FiPort.DAL.SqlClient.SqlMembershipProviderEx, __code"/>


class SqlMembershipProviderEx : 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);

}


}

}


protected void btnCreate_Click(object sender, EventArgs e)
{
MembershipProvider mp =
Membership.Providers["FiPort_MembershipProviderEx"];

MembershipCreateStatus status;

mp.CreateUser(this.txtServiceProviderID.Text, this.txtPassword.Text,
String.Empty,
String.Empty, String.Empty, true, null, out status);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top