In an ASP. NET project, want to leave a Super admin account.
If the user name of this super Administrator is fixed (for example, administrator), it is unsafe, so you want to generate a long string user name in this way, and change it once per hour.
year +superadmin + Total days + hour à MD5 encryption. Therefore, the user name changes every hour.
Using system;using system.text;using system.security.cryptography;namespace cki. jsonserver.models{ public class superadministratorhelper { public static string getname () { int year = DateTime.Now.Year; int month = DateTime.Now.Month; int day = DateTime.Now.Day; int hour = DateTime.Now.Hour; int sumdays = getdayofyear (month) + day; if (month > 2) { if (year % 4 == 0) && (year % 100 != 0) | | year % 400 == 0) { SumDays++; } } string sa = year + "Superadmin" + sumdays.tostring ("#000") + hour. ToString ("#00"); &nbSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;MD5 (SA); } public static string &NBSP;MD5 (STRING&NBSP;STR) { byte[] result = encoding.default.getbytes (str); MD5 md5 = new MD5CryptoServiceProvider (); byte[] output = md5. ComputeHash (result); string strmd5 = bitconverter.tostring (Output). Replace ("-", ""); return Strmd5; } &nBsp; private static int getdayofyear (int month/* value range: 1 to 12*/) { int SumDays = 0; if (month <= 0) return SumDays; switch (month - 1) { case 11: SumDays += 30; break; case 10: SumDays += 31; break; case 9: sumdays += 30; break; case 8: SumDays += 31; break; case 7: SumDays += 31; break; case 6: sumdays += 30; break; case 5: SumDays += 31; break; case 4: SumDays += 30; break; case 3: sumdays += 31; break; case 2: SumDays += 28; break; case 1: SumDays += 31; break; default: break; } sumdays += getdayofyear (month - 1); return SumDays; } }}
Generate a "change every hour" user name