using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for SturdsMembershipProvider
/// </summary>
public class SturdsMembershipProvider : MembershipProvider
{
private string _ApplicationName = "sturds";
private bool _EnablePasswordRetrieval = true;
private bool _EnablePasswordReset = true;
private UsersBLL _UsersBLL;
protected UsersBLL UsersBLL
{
get
{
if (_UsersBLL == null)
{
_UsersBLL = new UsersBLL();
}
return _UsersBLL;
}
}
public SturdsMembershipProvider()
{
}
public override bool ValidateUser(string username, string password)
{
DS.UserRow User = null;
DS.UserDataTable UserDataTable = UsersBLL.
GetDataByUsernameAndPassword(username, password);
if (UserDataTable.Rows.Count > 0)
{
User = (DS.UserRow)UserDataTable.Rows[0];
CurrentUser CurrentUser = new CurrentUser();
CurrentUser.UserID = User.ID;
}
return User != null;
}
public override string ApplicationName
{
get
{
return _ApplicationName;
}
set
{
_ApplicationName = value;
}
}
public override bool ChangePassword(string email, string oldPassword,
string newPassword)
{
/*
DS.UserRow User = UsersBLL.LoadForEmailAndPassword(email, oldPassword);
if (User.UserID == 0)
{
throw new ArgumentException(string.Format("User not found for
email: {0} and password", email));
}
User.Password = newPassword;
UsersBLL.Save(User);
*/
return true;
//TODO - ???
}
public override bool ChangePasswordQuestionAndAnswer(string username,
string password, string newPasswordQuestion, string newPasswordAnswer)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUser CreateUser(string username, string password,
string email, string passwordQuestion, string passwordAnswer, bool isApproved,
object providerUserKey, out MembershipCreateStatus status)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool DeleteUser(string username, bool deleteAllRelatedData)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool EnablePasswordReset
{
get
{
return _EnablePasswordReset;
}
}
public override bool EnablePasswordRetrieval
{
get
{
return _EnablePasswordRetrieval;
}
}
public override MembershipUserCollection FindUsersByEmail(string
emailToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUserCollection FindUsersByName(string
usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUserCollection GetAllUsers(int pageIndex, int
pageSize, out int totalRecords)
{
throw new Exception("The method or operation is not implemented.");
}
public override int GetNumberOfUsersOnline()
{
throw new Exception("The method or operation is not implemented.");
}
public override string GetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}
public override MembershipUser GetUser(string username, bool userIsOnline)
{
DS.UserRow User = null;
DS.UserDataTable UserDataTable = UsersBLL.GetDataByUserName(username);
if (UserDataTable.Rows.Count > 0)
{
User = (DS.UserRow)UserDataTable.Rows[0];
}
if (User == null)
{
return null;
}
else
{
return CreateUserFromUserRow(User);
}
}
private SturdsMembershipUser CreateUserFromUserRow(DS.UserRow User)
{
SturdsMembershipUser MembershipUser = new SturdsMembershipUser();
MembershipUser.UserID = User.ID;
//MembershipUser.UserName = User.Username;
return MembershipUser;
}
public override MembershipUser GetUser(object providerUserKey, bool
userIsOnline)
{
throw new Exception("The method or operation is not implemented.");
}
public override string GetUserNameByEmail(string email)
{
throw new Exception("The method or operation is not implemented.");
}
public override int MaxInvalidPasswordAttempts
{
get { throw new Exception("The method or operation is not implemented.");
}
}
public override int MinRequiredNonAlphanumericCharacters
{
get { throw new Exception("The method or operation is not implemented.");
}
}
public override int MinRequiredPasswordLength
{
get { throw new Exception("The method or operation is not implemented.");
}
}
public override int PasswordAttemptWindow
{
get { throw new Exception("The method or operation is not implemented.");
}
}
public override MembershipPasswordFormat PasswordFormat
{
get { return MembershipPasswordFormat.Clear; }
}
public override string PasswordStrengthRegularExpression
{
get { throw new Exception("The method or operation is not implemented.");
}
}
public override bool RequiresQuestionAndAnswer
{
//get { throw new Exception("The method or operation is not
implemented."); }
get { return false; }
}
public override bool RequiresUniqueEmail
{
get { throw new Exception("The method or operation is not implemented.");
}
}
public override string ResetPassword(string username, string answer)
{
throw new Exception("The method or operation is not implemented.");
}
public override bool UnlockUser(string userName)
{
throw new Exception("The method or operation is not implemented.");
}
public override void UpdateUser(MembershipUser user)
{
throw new Exception("The method or operation is not implemented.");
}
}
/* Inserire questo codice nel Web.Config */
<anonymousIdentification enabled="true"/>
<profile enabled="true">
<properties>
<add name="Dummy" allowAnonymous="true"/>
</properties>
</profile>
<authentication mode="Forms">
<forms loginUrl="Login.aspx" protection="All" timeout="25000">
</forms>
</authentication>
<membership defaultProvider="SturdsMembershipProvider">
<providers>
<add name="SturdsMembershipProvider"
type="SturdsMembershipProvider"></add>
</providers>
</membership>