当前位置: 首页>>代码示例>>C#>>正文


C# User.HashPassword方法代码示例

本文整理汇总了C#中User.HashPassword方法的典型用法代码示例。如果您正苦于以下问题:C# User.HashPassword方法的具体用法?C# User.HashPassword怎么用?C# User.HashPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在User的用法示例。


在下文中一共展示了User.HashPassword方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HashPassword

 protected string HashPassword(string password)
 {
     var user = new User();
     user.Password = password;
     user.HashPassword();
     return user.Password;
 }
开发者ID:r41lblast,项目名称:ndriven-cli,代码行数:7,代码来源:CreateDevelopmentUsers.cs

示例2: Register

        public ActionResult Register(RegisterInput input)
        {
            if (!ModelState.IsValid) return View(input);

            var user = new User() {Email = input.Email, Name = input.Name, Password = input.Password};
            user.HashPassword();

            Users.Store(user);

            Auth.Authenticate(user, ControllerContext.HttpContext.Response);

            return RedirectToAction("Index", "Home");
        }
开发者ID:r41lblast,项目名称:ndriven-cli,代码行数:13,代码来源:UserController.cs

示例3: Create

        public ActionResult Create(NewUserModel userModel, int[] roleIds)
        {
            User user = new User();

             try
             {
            if (ModelState.IsValid)
            {
               TryUpdateModel(userModel, new[] { "DisplayName", "Email", "Password", "PasswordConfirmation", "IsActive", "TimeZone", "AdminCulture" });

               // server validation
               string invalidMessage = string.Empty;

               // Unique Email
               if (userService.CountOtherUsersBySiteAndEmail(Context.ManagedSite, userModel.Email, user) > 0)
               {
                  invalidMessage = "Message_UserEmailIsNotUnique";
               }

               // Unique DisplayName Validation
               if (userService.CountOtherUsersBySiteAndDisplayName(Context.ManagedSite, userModel.DisplayName, user) > 0)
               {
                  invalidMessage = "Message_UserDisplayNameIsNotUnique";
               }

               if (invalidMessage.Length == 0)
               {
                  user.Password = user.HashPassword(userModel.Password);
                  user.PasswordConfirmation = user.HashPassword(userModel.PasswordConfirmation);

                  user.Roles.Clear();

                  if (roleIds != null && roleIds.Length > 0)
                  {
                     IList<Role> roles = userService.GetRolesByIds(roleIds);
                     foreach (Role role in roles)
                     {
                        user.Roles.Add(role);
                     }
                  }

                  user.Site = Context.ManagedSite;
                  user.CreatedDate = DateTime.UtcNow;

                  ServiceResult result = userService.SaveUser(user);

                  if (result.State == ServiceResult.ServiceState.Success)
                  {
                     // Show the confirmation message
                     MessageModel message = new MessageModel
                                               {
                                                  Text =
                                                     string.Format(GlobalResource("Message_UserCreated"),
                                                                   userModel.DisplayName),
                                                  Icon = MessageModel.MessageIcon.Info,
                                               };
                     RegisterMessage(message, true);

                     return RedirectToAction("Index");
                  }
                  else
                  {
                     MessageModel message = new MessageModel
                                               {
                                                  Text = GlobalResource(result.Message),
                                                  Icon = MessageModel.MessageIcon.Alert,
                                               };
                     RegisterMessage(message);
                  }
               }
               else
               {
                  MessageModel message = new MessageModel
                  {
                     Text = GlobalResource(invalidMessage),
                     Icon = MessageModel.MessageIcon.Alert,
                     CssClass = "margin-topbottom"
                  };
                  RegisterMessage(message);
               }

            }
             }
             catch (Exception ex)
             {
            log.Error("UsersController.Update", ex);

            MessageModel message = new MessageModel
                                    {
                                       Text = GlobalResource("Message_GenericError"),
                                       Icon = MessageModel.MessageIcon.Alert,
                                    };
            RegisterMessage(message);
             }

             userModel.Roles = user.Roles;
             userModel.AllRoles = userService.GetRolesBySite(Context.ManagedSite);
             userModel.TimeZones = new SelectList(TimeZoneUtil.GetTimeZones(), "Key", "Value", user.TimeZone);
             userModel.AdminThemes = new SelectList(GetAdminThemesList(), user.AdminTheme);
             userModel.Cultures = new SelectList(Globalization.GetOrderedCultures(), "Name", "DisplayName", user.AdminCulture);
//.........这里部分代码省略.........
开发者ID:aozora,项目名称:arashi,代码行数:101,代码来源:UsersController.cs

示例4: IsAuthenticated_should_return_true_for_matching_unhashed_password

 public void IsAuthenticated_should_return_true_for_matching_unhashed_password()
 {
     var user = new User() {Password = "password"};
     user.HashPassword();
     Assert.True(user.IsAuthenticated("password"));
 }
开发者ID:r41lblast,项目名称:ndriven-cli,代码行数:6,代码来源:UserTest.cs

示例5: IsAuthenticated_should_return_fals_for_non_matching_unhashed_password

 public void IsAuthenticated_should_return_fals_for_non_matching_unhashed_password()
 {
     var user = new User() { Password = "password" };
     user.HashPassword();
     Assert.False(user.IsAuthenticated("false"));
 }
开发者ID:r41lblast,项目名称:ndriven-cli,代码行数:6,代码来源:UserTest.cs

示例6: HashPassword_should_hash_unhashed_password

 public void HashPassword_should_hash_unhashed_password()
 {
     var user = new User() {Password = "password"};
     user.HashPassword();
     Assert.IsTrue(BCryptHelper.CheckPassword("password", user.Password));
 }
开发者ID:r41lblast,项目名称:ndriven-cli,代码行数:6,代码来源:UserTest.cs


注:本文中的User.HashPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。