private static UserInfo CreateUserContextFromUser(User user)
        {
            var userContext = new UserInfo
                              {
                                  UserId = user.UserId,
                                  DisplayName = user.DisplayName,
                                  UserIdentifier = user.Email,
                                  RoleName = Enum.GetName(typeof (UserRoles), user.RoleId)
                              };

            return userContext;
        }
        public static FormsAuthenticationTicket CreateAuthenticationTicket(User user)
        {
            UserInfo userInfo = CreateUserContextFromUser(user);

            var ticket = new FormsAuthenticationTicket(
                1,
                user.FirstName,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                false,
                userInfo.ToString());

            return ticket;
        }
示例#3
0
 private bool ValidatePassword(User user, string password)
 {
     var encoded = Md5Encrypt.Md5EncryptPassword(password);
     return user.PasswordHash.Equals(encoded);
 }