CustomAuthClasses.cs
使用系统;
使用的System.Web;
使用System.Web.Security;命名空间CustomAuthRepurposingFormsAuth
{
公共静态类TicketHelper
{
///<总结>
///
///< /总结>
///< PARAM NAME =“username”的>< /参数>
///< PARAM NAME =“用户数据”>铭记饼干大小,或者你会追鬼< /参数>
///< PARAM NAME =“老大难”>< /参数>
///<&回报GT;< /回报>
公共静态的HttpCookie CreateAuthCookie(用户名字符串,字符串用户数据,布尔持久)
{
日期时间发出= DateTime.Now;
// formsAuth不公开超时!?有破解绕
//被宠坏的部件和保持运动..
的HttpCookie fooCookie = FormsAuthentication.GetAuthCookie(“富”,真正的);
INT formsTimeout = Convert.ToInt32((fooCookie.Expires - DateTime.Now).TotalMinutes); 日期时间过期= DateTime.Now.AddMinutes(formsTimeout);
字符串cookiePath = FormsAuthentication.FormsCookiePath; VAR票=新的FormsAuthenticationTicket(0,用户名,发行,到期,真实,用户数据,cookiePath);
返回CreateAuthCookie(门票,有效期,持久性的);
} 公共静态的HttpCookie CreateAuthCookie(门票的FormsAuthenticationTicket,日期过期,布尔持久)
{
字符串creamyFilling = FormsAuthentication.Encrypt(票);
VAR饼干=新的HttpCookie(FormsAuthentication.FormsCookieName,creamyFilling)
{
域= FormsAuthentication.CookieDomain,
路径= FormsAuthentication.FormsCookiePath
};
如果(持久)
{
cookie.Expires =到期;
} 返回的cookie;
}
} ///<总结>
///这是继承来的MembershipUser的例子
///揭露了可伴有任意数据的
///用户执行。
///
///你可以重新利用的基础上,现有油田,并添加你自己的。
///只需进行一次造型上从的MembershipUser你回来
///的MembershipProvider实现
///< /总结>
公共类MyMembershipUser:的MembershipUser
{
公共MyMembershipUser(字符串的providerName,字符串名称,对象providerUserKey,字符串email,
串passwordQuestion,字符串评论,布尔isApproved,布尔isLockedOut,
日期时间creationDate,日期时间lastLoginDate,日期时间lastActivityDate,
日期时间lastPasswordChangedDate,日期lastLockoutDate)
:基地(
的providerName,名称,providerUserKey,电子邮件,passwordQuestion,评论,isApproved,isLockedOut,
creationDate,lastLoginDate,lastActivityDate,lastPasswordChangedDate,lastLockoutDate)
{
} 保护MyMembershipUser()
{
} //例如不希望使用,只需要添加数据
//说,从包含所有用户数据平面记录
公共字符串MyCustomField {搞定;组; }
} ///<总结>
///在最基本的层面上,实施了的MembershipProvider让你
///重用既定框架code。在这种情况下,我们只是提供服务
///通过成员子系统的登录控制和用户标识。
///< /总结>
公共类MyMembershipProvider:的MembershipProvider
{
为了#地区最小的方案中使用已经建立的认证和鉴定的基础设施 ///<总结>
///你可以做这样的登录逻辑,如果你不想
///入会用户访问杠杆框架
///< /总结>
公众覆盖布尔的ValidateUser(用户名字符串,字符串密码)
{
返回用户名密码==;
}
公众覆盖的MembershipUser的getUser(用户名字符串,布尔userIsOnline)
{
/ *
*模拟将获取数据
* / //会员用户为空的无域,重新利用或使用
//隐含的空值例如DateTime.MinValue; VAR createdDate =新日期时间(2009年,10,25);
VAR lastLogin =新日期时间(2009年,10,25);
VAR lastActivity =新日期时间(2009年,10,25);
VAR lastPasswordChange =新日期时间(2009年,10,25);
VAR lastLockoutDate =新日期时间(2009年,10,25); 反对providerUserKey = 3948; //例如用户的主键。
/ *
*建立你自定义的用户,并发送回asp.net
* / //需要使用完整的构造函数来设置用户名和密钥
VAR用户=新MyMembershipUser(名称,用户名,providerUserKey,NULL,NULL,NULL,真,假createdDate,
上次登录,
lastActivity,lastPasswordChange,lastLockoutDate)
{
MyCustomField =“嗨”
}; 返回用户;
} #endregion 根据该框架#地区的可选功能的实现要充分利用。 公众覆盖布尔EnablePasswordRetrieval
{
获得{抛出新NotImplementedException(); }
} 公众覆盖布尔enablePasswordReset设置
{
获得{抛出新NotImplementedException(); }
} 公众覆盖布尔RequiresQuestionAndAnswer
{
获得{抛出新NotImplementedException(); }
} 公众覆盖字符串的应用程序名称
{
获得{抛出新NotImplementedException(); }
集合{抛出新NotImplementedException(); }
} 公共覆盖INT MaxInvalidPasswordAttempts
{
获得{抛出新NotImplementedException(); }
} 公共覆盖INT PasswordAttemptWindow
{
获得{抛出新NotImplementedException(); }
} 公众覆盖布尔RequiresUniqueEmail
{
获得{抛出新NotImplementedException(); }
} 公众覆盖MembershipPasswordFormat了passwordFormat
{
获得{抛出新NotImplementedException(); }
} 公共覆盖INT MinRequiredPasswordLength
{
获得{抛出新NotImplementedException(); }
} 公共覆盖INT MinRequiredNonAlphanumericCharacters
{
获得{抛出新NotImplementedException(); }
} 公共重写字符串PasswordStrengthRegularEx pression
{
获得{抛出新NotImplementedException(); }
} 公众覆盖的MembershipUser的getUser(对象providerUserKey,布尔userIsOnline)
{
抛出新NotImplementedException();
}
公众覆盖的MembershipUser CREATEUSER(用户名字符串,字符串密码,串电子邮件,
串passwordQuestion,串passwordAnswer,布尔isApproved,
对象providerUserKey,出MembershipCreateStatus状态)
{
抛出新NotImplementedException();
} 公众覆盖布尔ChangePasswordQuestionAndAnswer(用户名字符串,字符串密码,
串newPasswordQuestion,串newPasswordAnswer)
{
抛出新NotImplementedException();
} 公众覆盖字符串用户注册忘记密码(用户名字符串,字符串的答案)
{
抛出新NotImplementedException();
} 公众覆盖布尔的ChangePassword(用户名字符串,字符串旧密码,串NEWPASSWORD)
{
抛出新NotImplementedException();
} 公众覆盖字符串ResetPassword(用户名字符串,字符串的答案)
{
抛出新NotImplementedException();
} 公共覆盖无效UpdateUser两个(用户的MembershipUser)
{
抛出新NotImplementedException();
} 公众覆盖布尔UnlockUser(用户名字符串)
{
抛出新NotImplementedException();
}
公众覆盖字符串GetUserNameByEmail(字符串email)
{
抛出新NotImplementedException();
} 公众覆盖布尔DeleteUser(用户名字符串,布尔deleteAllRelatedData)
{
抛出新NotImplementedException();
} 公众覆盖MembershipUserCollection GetAllUsers(INT的PageIndex,诠释的pageSize,OUT INT总记录)
{
抛出新NotImplementedException();
} 公共覆盖INT GetNumberOfUsersOnline()
{
抛出新NotImplementedException();
} 公众覆盖MembershipUserCollection FindUsersByName(字符串的usernameToMatch,诠释的PageIndex,诠释的pageSize,
OUT INT共条记录)
{
抛出新NotImplementedException();
} 公众覆盖MembershipUserCollection FindUsersByEmail(字符串emailToMatch,诠释的PageIndex,诠释的pageSize,
OUT INT共条记录)
{
抛出新NotImplementedException();
} #endregion
}
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-51660-9.html
民族生存都难以做到
连1900也没有