using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Net.Mail;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using oslcwb.common;
/// <summary>
/// Summary description for AccessMembershipProvider
/// </summary>
public class AccessMembershipProvider: MembershipProvider
{
private Database _database;
private Boolean _requiresQuestionAndAnswer;
private int _minRequiredPasswordLength;
public AccessMembershipProvider()
{
//
// TODO: Add constructor logic here
//
}
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
if (config["requiresQuestionAndAnswer"].Equals("true", StringComparison.InvariantCultureIgnoreCase))
_requiresQuestionAndAnswer = true;
_database = new Database(config["connectionString"]);
base.Initialize(name, config);
}
public override string ApplicationName
{
get
{
throw new Exception("The method or operation is not implemented.");
}
set
{
throw new Exception("The method or operation is not implemented.");
}
}
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
throw new Exception("The method or operation is not implemented.");
}
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 { throw new Exception("The method or operation is not implemented."); }
}
public override bool EnablePasswordRetrieval
{
get { throw new Exception("The method or operation is not implemented."); }
}
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)
{
throw new Exception("The method or operation is not implemented.");
}
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 { throw new Exception("The method or operation is not implemented."); }
}
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."); }
}
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.");
}
public override bool ValidateUser(string username, string password)
{
try
{
string sql = "Select USER_ID From [USER] WHERE USER_NAME=@username AND USER_PASSWORD=@password";
OleDbParameter[] paramArray = new OleDbParameter[2];
paramArray[0] = new OleDbParameter("@username", OleDbType.VarChar);
paramArray[1] = new OleDbParameter("@password", OleDbType.VarChar);
paramArray[0].Value = username;
paramArray[1].Value = password;
DataTable dt = _database.Execute(sql, paramArray);
if (dt.Rows.Count == 1)
{
return true;
}
else
{
//Send me an email with login attempt info
MailMessage pReqMail = new MailMessage();
pReqMail.From = new MailAddress("webmaster@oslcwb.org");
pReqMail.To.Add("kevin.klika@charter.net");
pReqMail.Subject = "OSLCWB.ORG Failed Login Attempt - '" + DateTime.Now.ToLongDateString() + "...'";
pReqMail.Body = "" +
"<div style='background-color: #ccc; border:solid 1px #9999ff'>" +
"<p>A Failed Login Attempt has been Logged. Data Stack Follows:</p>" +
"<p style='font-size:20px; background-color:#ccf; padding:2px 10px 2px 10px; margin: 0px 0px 0px 0px; border-bottom: solid 1px #99f;'>" +
"<br />Username entered: "+username.ToString() +
"<br />Password entered: "+password.ToString() +
"</p>";
pReqMail.IsBodyHtml = true;
//Send the message
SmtpClient smtp = new SmtpClient("oslcwb.org");
smtp.Send(pReqMail);
return false;
}
}
catch (Exception ex)
{
//TODO: need to send email to myself with error information
throw ex;
}
}
}