【发布时间】:2014-05-14 11:44:39
【问题描述】:
我正在尝试创建数据库中尚不存在的唯一激活码。我的问题是如何测试这个?
我尝试使用断点,然后将 db 表更改为新结果,但没有成功
private string CreateActivationCode()
{
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random = new Random();
string result = new string(
Enumerable.Repeat(chars, 4)
.Select(s => s[random.Next(s.Length)])
.ToArray());
IEnumerable<string> existingActivationKeys = _mobileDeviceService.GetAll().Select(x => x.UsageKey).ToList();
if (existingActivationKeys.Contains(result))
{
//USE GO TO????
CreateUsageKey();
}
return result;
}
【问题讨论】:
-
这只给你 26^4 个代码,够了吗?可能有比您现在的方式更好的方法来执行此操作...您是否考虑过使用 GUID?
-
您是在问如何最好地生成唯一密钥,还是在问如何测试您发布的方法?
标签: c# asp.net-mvc asp.net-mvc-3 key activation