本文整理汇总了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;
}
示例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");
}
示例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);
//.........这里部分代码省略.........
示例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"));
}
示例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"));
}
示例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));
}