本文整理汇总了C#中TShockAPI.DB.User.CreateBCryptHash方法的典型用法代码示例。如果您正苦于以下问题:C# User.CreateBCryptHash方法的具体用法?C# User.CreateBCryptHash怎么用?C# User.CreateBCryptHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TShockAPI.DB.User
的用法示例。
在下文中一共展示了User.CreateBCryptHash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterUser
private static void RegisterUser(CommandArgs args)
{
try
{
var user = new User();
string echoPassword = "";
if (args.Parameters.Count == 1)
{
user.Name = args.Player.Name;
echoPassword = args.Parameters[0];
try
{
user.CreateBCryptHash(args.Parameters[0]);
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("Password must be greater than or equal to " + TShock.Config.MinimumPasswordLength + " characters.");
return;
}
}
else if (args.Parameters.Count == 2 && TShock.Config.AllowRegisterAnyUsername)
{
user.Name = args.Parameters[0];
echoPassword = args.Parameters[1];
try
{
user.CreateBCryptHash(args.Parameters[1]);
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("Password must be greater than or equal to " + TShock.Config.MinimumPasswordLength + " characters.");
return;
}
}
else
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: {0}register <password>", Specifier);
return;
}
user.Group = TShock.Config.DefaultRegistrationGroupName; // FIXME -- we should get this from the DB. --Why?
user.UUID = args.Player.UUID;
if (TShock.Users.GetUserByName(user.Name) == null && user.Name != TSServerPlayer.AccountName) // Cheap way of checking for existance of a user
{
args.Player.SendSuccessMessage("Account \"{0}\" has been registered.", user.Name);
args.Player.SendSuccessMessage("Your password is {0}.", echoPassword);
TShock.Users.AddUser(user);
TShock.Log.ConsoleInfo("{0} registered an account: \"{1}\".", args.Player.Name, user.Name);
}
else
{
args.Player.SendErrorMessage("Account " + user.Name + " has already been registered.");
TShock.Log.ConsoleInfo(args.Player.Name + " failed to register an existing account: " + user.Name);
}
}
catch (UserManagerException ex)
{
args.Player.SendErrorMessage("Sorry, an error occured: " + ex.Message + ".");
TShock.Log.ConsoleError("RegisterUser returned an error: " + ex);
}
}
示例2: ManageUsers
private static void ManageUsers(CommandArgs args)
{
// This guy needs to be here so that people don't get exceptions when they type /user
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("Invalid user syntax. Try {0}user help.", Specifier);
return;
}
string subcmd = args.Parameters[0];
// Add requires a username, password, and a group specified.
if (subcmd == "add" && args.Parameters.Count == 4)
{
var user = new User();
user.Name = args.Parameters[1];
try
{
user.CreateBCryptHash(args.Parameters[2]);
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("Password must be greater than or equal to " + TShock.Config.MinimumPasswordLength + " characters.");
return;
}
user.Group = args.Parameters[3];
try
{
TShock.Users.AddUser(user);
args.Player.SendSuccessMessage("Account " + user.Name + " has been added to group " + user.Group + "!");
TShock.Log.ConsoleInfo(args.Player.Name + " added Account " + user.Name + " to group " + user.Group);
}
catch (GroupNotExistsException)
{
args.Player.SendErrorMessage("Group " + user.Group + " does not exist!");
}
catch (UserExistsException)
{
args.Player.SendErrorMessage("User " + user.Name + " already exists!");
}
catch (UserManagerException e)
{
args.Player.SendErrorMessage("User " + user.Name + " could not be added, check console for details.");
TShock.Log.ConsoleError(e.ToString());
}
}
// User deletion requires a username
else if (subcmd == "del" && args.Parameters.Count == 2)
{
var user = new User();
user.Name = args.Parameters[1];
try
{
TShock.Users.RemoveUser(user);
args.Player.SendSuccessMessage("Account removed successfully.");
TShock.Log.ConsoleInfo(args.Player.Name + " successfully deleted account: " + args.Parameters[1] + ".");
}
catch (UserNotExistException)
{
args.Player.SendErrorMessage("The user " + user.Name + " does not exist! Deleted nobody!");
}
catch (UserManagerException ex)
{
args.Player.SendErrorMessage(ex.Message);
TShock.Log.ConsoleError(ex.ToString());
}
}
// Password changing requires a username, and a new password to set
else if (subcmd == "password" && args.Parameters.Count == 3)
{
var user = new User();
user.Name = args.Parameters[1];
try
{
TShock.Users.SetUserPassword(user, args.Parameters[2]);
TShock.Log.ConsoleInfo(args.Player.Name + " changed the password of account " + user.Name);
args.Player.SendSuccessMessage("Password change succeeded for " + user.Name + ".");
}
catch (UserNotExistException)
{
args.Player.SendErrorMessage("User " + user.Name + " does not exist!");
}
catch (UserManagerException e)
{
args.Player.SendErrorMessage("Password change for " + user.Name + " failed! Check console!");
TShock.Log.ConsoleError(e.ToString());
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("Password must be greater than or equal to " + TShock.Config.MinimumPasswordLength + " characters.");
}
}
// Group changing requires a username or IP address, and a new group to set
else if (subcmd == "group" && args.Parameters.Count == 3)
{
//.........这里部分代码省略.........
示例3: RegisterUser
private static void RegisterUser(CommandArgs args)
{
try
{
var user = new User();
string echoPassword = "";
if (args.Parameters.Count == 1)
{
user.Name = args.Player.Name;
echoPassword = args.Parameters[0];
try
{
user.CreateBCryptHash(args.Parameters[0]);
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("密码至少要有" + TShock.Config.MinimumPasswordLength + "个字符。");
return;
}
}
else if (args.Parameters.Count == 2 && TShock.Config.AllowRegisterAnyUsername)
{
user.Name = args.Parameters[0];
echoPassword = args.Parameters[1];
try
{
user.CreateBCryptHash(args.Parameters[1]);
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("密码至少要有" + TShock.Config.MinimumPasswordLength + "个字符。");
return;
}
}
else
{
args.Player.SendErrorMessage("格式错误。 格式: {0}注册 <密码>", Specifier);
return;
}
user.Group = TShock.Config.DefaultRegistrationGroupName; // FIXME -- we should get this from the DB. --Why?
user.UUID = args.Player.UUID;
if (TShock.Users.GetUserByName(user.Name) == null && user.Name != TSServerPlayer.AccountName) // Cheap way of checking for existance of a user
{
args.Player.SendSuccessMessage("用户 \"{0}\" 已被注册。请直接登录或换玩家名进行游戏。", user.Name);
args.Player.SendSuccessMessage("你的密码是{0}。", echoPassword);
TShock.Users.AddUser(user);
TShock.Log.ConsoleInfo("{0} 注册了 \"{1}\"。", args.Player.Name, user.Name);
}
else
{
args.Player.SendErrorMessage("用户 " + user.Name + " 已被注册。");
TShock.Log.ConsoleInfo(args.Player.Name + " 试图注册 " + user.Name + " 失败。");
}
}
catch (UserManagerException ex)
{
args.Player.SendErrorMessage("发生错误: " + ex.Message + "。");
TShock.Log.ConsoleError("RegisterUser发生错误: " + ex);
}
}
示例4: SetUserPassword
/// <summary>
/// Sets the Hashed Password for a given username
/// </summary>
/// <param name="user">User user</param>
/// <param name="password">string password</param>
public void SetUserPassword(User user, string password)
{
try
{
user.CreateBCryptHash(password);
if (
_database.Query("UPDATE Users SET Password = @0 WHERE Username = @1;", user.Password,
user.Name) == 0)
throw new UserNotExistException(user.Name);
}
catch (Exception ex)
{
throw new UserManagerException("SetUserPassword SQL returned an error", ex);
}
}
示例5: ManageUsers
private static void ManageUsers(CommandArgs args)
{
// This guy needs to be here so that people don't get exceptions when they type /user
if (args.Parameters.Count < 1)
{
args.Player.SendErrorMessage("格式错误。 输入'{0}用户 help' 查看帮助", Specifier);
return;
}
string subcmd = args.Parameters[0];
// Add requires a username, password, and a group specified.
if (subcmd == "add" && args.Parameters.Count == 4)
{
var user = new User();
user.Name = args.Parameters[1];
try
{
user.CreateBCryptHash(args.Parameters[2]);
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("密码至少要有" + TShock.Config.MinimumPasswordLength + "个字符。");
return;
}
user.Group = args.Parameters[3];
try
{
TShock.Users.AddUser(user);
args.Player.SendSuccessMessage("用户 " + user.Name + " 被添加到组 " + user.Group + "中。");
TShock.Log.ConsoleInfo(args.Player.Name + " 添加用户 " + user.Name + " 到组 " + user.Group + "中。");
}
catch (GroupNotExistsException)
{
args.Player.SendErrorMessage("用户组 " + user.Group + " 不存在。");
}
catch (UserExistsException)
{
args.Player.SendErrorMessage("用户 " + user.Name + " 已经存在。");
}
catch (UserManagerException e)
{
args.Player.SendErrorMessage("无法添加用户 " + user.Name + " ,查看后台获得更多信息。");
TShock.Log.ConsoleError(e.ToString());
}
}
// User deletion requires a username
else if (subcmd == "del" && args.Parameters.Count == 2)
{
var user = new User();
user.Name = args.Parameters[1];
try
{
TShock.Users.RemoveUser(user);
args.Player.SendSuccessMessage("用户删除成功。");
TShock.Log.ConsoleInfo(args.Player.Name + " 删除了用户 " + args.Parameters[1] + "。");
}
catch (UserNotExistException)
{
args.Player.SendErrorMessage("用户 " + user.Name + " 不存在。");
}
catch (UserManagerException ex)
{
args.Player.SendErrorMessage(ex.Message);
TShock.Log.ConsoleError(ex.ToString());
}
}
// Password changing requires a username, and a new password to set
else if (subcmd == "password" && args.Parameters.Count == 3)
{
var user = new User();
user.Name = args.Parameters[1];
try
{
TShock.Users.SetUserPassword(user, args.Parameters[2]);
TShock.Log.ConsoleInfo(args.Player.Name + " 修改了 " + user.Name + " 的密码。");
args.Player.SendSuccessMessage("成功修改了 " + user.Name + " 的密码。");
}
catch (UserNotExistException)
{
args.Player.SendErrorMessage("用户 " + user.Name + " 不存在。");
}
catch (UserManagerException e)
{
args.Player.SendErrorMessage("无法修改用户 " + user.Name + " 的密码,查看后台获得更多信息。");
TShock.Log.ConsoleError(e.ToString());
}
catch (ArgumentOutOfRangeException)
{
args.Player.SendErrorMessage("密码至少要有" + TShock.Config.MinimumPasswordLength + "个字符。");
}
}
// Group changing requires a username or IP address, and a new group to set
else if (subcmd == "group" && args.Parameters.Count == 3)
{
//.........这里部分代码省略.........