473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Custom Membership Provider

Ron
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.SqlMembershipProvide rEx, __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);

}
Jul 5 '06 #1
4 7886
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/de...ovMod_Prt1.asp

Peter

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


"Ron" wrote:
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.SqlMembershipProvide rEx, __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);

}
Jul 5 '06 #2
Ron
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 [C# MVP]" wrote:
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/de...ovMod_Prt1.asp

Peter

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


"Ron" wrote:
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.SqlMembershipProvide rEx, __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);

}
Jul 5 '06 #3
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" wrote:
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 [C# MVP]" wrote:
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/de...ovMod_Prt1.asp

Peter

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


"Ron" wrote:
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.SqlMembershipProvide rEx, __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);
>
}
Jul 6 '06 #4
Ron
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 [C# MVP]" wrote:
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" wrote:
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 [C# MVP]" wrote:
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/de...ovMod_Prt1.asp
>
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"Ron" wrote:
>
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.SqlMembershipProvide rEx, __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);

}
Jul 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
6
by: Shimon Sim | last post by:
Hi I am working on application that need to hold custom user information - Last and first name, email, some other domain related information. I used to create Base class for all my pages. The base...
2
by: WB | last post by:
Hi, I am revamping my company's website with ASP.Net 2.0. In order to use our existing user data in our SQL 2000, I have written a custom membership provider. However, when I try to logon with...
2
by: John | last post by:
Hi I was working fine with create user wizard and the default membership provider. I have now customised the membership provider as per attached web.config. The create user wizard picks up the...
4
by: techsupport | last post by:
I have some experience with .NET Remoting, as well as ASP.NET 2.0, and have been wanting to remote a custom membership and profile provider. I want to take advantage of the new controls in ASP.NET...
1
by: Axford | last post by:
Hello, I am trying to implement my own custom provider for memberships, basically only id/pwd (no roles). I use the new login web control (I am using asp.net 2.0 and VS2005). In web.config I...
0
by: Mwob | last post by:
Hi all, I'm about to start creating a custom membership provider. Its for a website that already has a table of users in a single table, so I need to create a custom MP to talk to the data in...
4
by: alexandis | last post by:
We have tables of logins (users), that differs much from standard microsoft structure - we don't use control question/answer, date fields, etc. But instead we have several additional fields. I...
3
by: Sunfire | last post by:
I need to use a custom database for all of the user membership and rolls. How do you do this?
6
by: Jonathan Wood | last post by:
Although this will be a challenge at my level of ASP.NET knowledge, I'm thinking I should implement my own membership provider class. Looking over the methods I must implement, a number of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.