使用会员提供商验证用户
我正在我的应用程序 Asp.net MVC 3 中自定义一种用户验证形式。
如何实现 ValidateUser
方法?
我的问题是 MembershipUser
类(我也自定义)的密码有一个 Password 属性。
我正在使用 EF CodeFirst .. 以下代码:
MembershipUser
public class User : MembershipUser
{
public User(string username, object providerUserKey, string email, string passwordQuestion, bool isApproved,
bool isLockedOut)
: base("", username, providerUserKey, email, passwordQuestion, "", isApproved, isLockedOut, DateTime.Now, DateTime.MinValue,
DateTime.Now, DateTime.MinValue, DateTime.MinValue)
{
}
}
MembershipProvider
public class UserProvider : MembershipProvider
{
public override bool ValidateUser(string email, string password)
{
var bytes = new ASCIIEncoding().GetBytes(password);
var encryptedPassword = EncryptPassword(bytes);
using (var db = new DataContext())
{
var user = from u in db.Users
where u.Email == email
/* How to compare password? */
}
}
}
请问,是否有关于此类实现的完整文章?
I'm customizing a form of validation of the users in my application Asp.net MVC 3.
How can I implement the method ValidateUser
?
My problem is the password for the MembershipUser
class (which I also customize) has a Password property.
I'm using EF CodeFirst .. following code:
MembershipUser
public class User : MembershipUser
{
public User(string username, object providerUserKey, string email, string passwordQuestion, bool isApproved,
bool isLockedOut)
: base("", username, providerUserKey, email, passwordQuestion, "", isApproved, isLockedOut, DateTime.Now, DateTime.MinValue,
DateTime.Now, DateTime.MinValue, DateTime.MinValue)
{
}
}
MembershipProvider
public class UserProvider : MembershipProvider
{
public override bool ValidateUser(string email, string password)
{
var bytes = new ASCIIEncoding().GetBytes(password);
var encryptedPassword = EncryptPassword(bytes);
using (var db = new DataContext())
{
var user = from u in db.Users
where u.Email == email
/* How to compare password? */
}
}
}
Please, is there a complete article with the implementation of this class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有完整的例子,但这对你不起作用吗?
I have not got a complete example but will this not work for you?