添加项目文件。
This commit is contained in:
45
Tool/GenerateTool.cs
Normal file
45
Tool/GenerateTool.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace WebAppServer1.Tool
|
||||
{
|
||||
public class GenerateTool
|
||||
{
|
||||
public static string GeneratePassword()
|
||||
{
|
||||
const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const string digits = "0123456789";
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// 生成 2 个字母
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
int index = RandomNumberGenerator.GetInt32(letters.Length);
|
||||
sb.Append(letters[index]);
|
||||
}
|
||||
|
||||
// 生成 4 个数字
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
int index = RandomNumberGenerator.GetInt32(digits.Length);
|
||||
sb.Append(digits[index]);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string GenerateRandomNickname()
|
||||
{
|
||||
string[] part1 = { "自由的", "快乐的", "孤独的", "勇敢的", "神秘的" };
|
||||
string[] part2 = { "小鸟", "星星", "花朵", "少年", "旅人" };
|
||||
string[] part3 = { "在唱歌", "在飞翔", "在微笑", "在流浪", "在思考" };
|
||||
|
||||
var random = new Random();
|
||||
string nickname = part1[random.Next(part1.Length)]
|
||||
+ part2[random.Next(part2.Length)]
|
||||
+ part3[random.Next(part3.Length)];
|
||||
return nickname;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user