我必须创建一个实时报告.为此,我必须为某一天的每一小时写下条件.在下面的代码中,条件检查当前星期几,然后检查当前时间并根据必须生成报告.
protected void sample()
{
TimeSpan zerothHour = new TimeSpan(00, 0, 0);
TimeSpan firstHour = new TimeSpan(01, 0, 0);
TimeSpan secondHour = new TimeSpan(02, 0, 0);
TimeSpan thirdHour = new TimeSpan(03, 0, 0);
TimeSpan fourthHour = new TimeSpan(04, 0, 0);
TimeSpan fifthHour = new TimeSpan(05, 0, 0);
TimeSpan sixthHour = new TimeSpan(06, 0, 0);
// and so on until the twentyfourth hour
if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
{
if (DateTime.Now.TimeOfDay >= sixthHour && DateTime.Now.TimeOfDay <= seventhHour)
{
//MySql query here
string …
Run Code Online (Sandbox Code Playgroud) 我使用以下方法对密码进行加盐和哈希处理
public string CreateSalt(int size)
{
var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
var buff = new byte[size];
rng.GetBytes(buff);
return Convert.ToBase64String(buff);
}
public string GenerateSHA256Hash(String input, String salt)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(input + salt);
System.Security.Cryptography.SHA256Managed sha256hashstring =
new System.Security.Cryptography.SHA256Managed();
byte[] hash = sha256hashstring.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
public void Submit1_click(object sender, EventArgs r)
{
try
{
String salt = CreateSalt(10);
String hashedpassword = GenerateSHA256Hash(password1.Text, salt);
string MyConString = "SERVER=localhost;DATABASE=mydb;UID=root;PASSWORD=abc123;";
MySqlConnection connection = new MySqlConnection(MyConString);
string cmdText = "INSERT INTO authentication(agentlogin ,password ,question …
Run Code Online (Sandbox Code Playgroud)