I always used my own code to create logins and registers but using memberships should save me a lot of time in programming these things in my following projects.
Now i've found many tutorials on implementing your own custom membership and some of them are way different than others. And i am having a hard time to understand what the best solution is for implementing a simple custom membership implementation.
For this project i just need to add some additional user information, like a streetname, postcode etc.
What i've currently made is this:
public class CustomMembershipUser : MembershipUser
{
public CustomMembershipUser(
string providerName,
string name,
object providerUserKey,
string email,
string passwordQuestion,
string comment,
bool isApproved,
bool isLockedOut,
DateTime creationDate,
DateTime lastLoginDate,
DateTime lastActivityDate,
DateTime lastPasswordChangedDate,
DateTime lastLockoutDate
)
: base(providerName, name, providerUserKey, email, passwordQuestion,
comment, isApproved, isLockedOut, creationDate, lastLoginDate,
lastActivityDate, lastPasswordChangedDate, lastLockoutDate)
{
}
// Add additional properties
public string Streetname { get; set; }
public string Postcode { get; set; }
}
public abstract class CustomMembershipProvider : MembershipProvider
{
public override MembershipUser GetUser(string username, bool userIsOnline)
{
// get data logic
var user = new CustomMembershipUser(
"CustomMembershipProvider",
"naam",
"1",
"adasd@live.com",
"",
"",
true,
false,
DateTime.Now,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue) { Streetname = "Test", Postcode = "Test2"};
return user;
}
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer,
bool isApproved, object providerUserKey, out MembershipCreateStatus status)
{
var user = new CustomMembershipUser(
"CustomMembershipProvider",
"naam",
"1",
"adasd@live.com",
"",
"",
true,
false,
DateTime.Now,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue,
DateTime.MinValue) { Streetname = "Test", Postcode = "Test2" };
status = MembershipCreateStatus.Success;
return user;
}
}
Is this the best solution for my custom membership or are there better options?
I have not tested this yet, so i have no idea if this works.
I'm using MVC 4.