Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate a user name that changes every hour in C #

Shulou Source: shulou.com Published: 2022-06-02 11:50:28 09月17日 Update

This article will explain in detail how to generate an hourly user name in c#. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

I am working on an ASP.NET project and want to keep a super admin account.

If the user name of the super administrator is fixed (for example, administrator), this is not safe; so you want to generate a long string user name in the following way and change it every hour.

The composition of the user name: year + total days of SuperAdmin+ + hours à for MD5 encryption. As a result, the user name changes from hour to 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") Return MD5 (sa);} public static string MD5 (string str) {byte [] result = Encoding.Default.GetBytes (str); MD5 md5 = new MD5CryptoServiceProvider (); byte [] output = md5.ComputeHash (result); string strMD5 = BitConverter.ToString (output) .replace ("-", "); return strMD5 } private static int GetDayOfYear (int month/* value range: 1 to 12 seconds /) {int SumDays = 0; if (month

Tags: Users usernames hours changes generation articles caches more administrators administrators good practical security content days characters strings articles methods knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS MySQL Redmi Xiaomi