Best way to generate activation codes for software?

前提是你 提交于 2019-12-20 01:04:02

问题


What is a good way to randomly generate some not-likely-to-be-randomly-generated-again activation codes to use for activating software? I am making an auto-fulfillment system for a web application.

I am using C#.


回答1:


Guid.NewGuid()




回答2:


It depends on your goals. A GUID is simple to generate, but it's a pain if the user has to enter it manually. That's fine if activation is happening by (say) clicking on a URL provided in email, or if you can expect the user to copy and paste a value from an activation email.

In other cases (e.g. shrinkwrapped software where the activation code is physically printed on the packaging in some manner), the user will be manually entering the code. In this case, you're better off using a method akin to what Microsoft and Blizzard use: generate a code consisting of five groups of five random alphanumeric characters (omit vowels if you want to eliminate the risk that an activation code will contains something like 4SHIT), and check each code generated against a master list for duplicates. (Though I think the odds of even a 100,000-sequence extracted from {1, 2, ... 34^26 - 1} containing a duplicate are pretty small. It's hard to say for sure, because the only way I know of calculating it overflows a double.)




回答3:


Guid.NewGuid().ToString()

If you don't mind a 36 character length.




回答4:


You should probably just use a Guid



来源:https://stackoverflow.com/questions/1336941/best-way-to-generate-activation-codes-for-software

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!