Generate a "change every hour" user name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.