public AccountModel Create(string Acc, string Pass, string Conn) { AccountModel result = new AccountModel(); using (MySqlConnection conn = new MySqlConnection(Conn)){ SQLs.Clear(); SQLs.AppendLine("SELECT * "); SQLs.AppendLine("FROM CoreMVCBackend.Account "); SQLs.AppendLine("WHERE Account_Account=@Account_Account "); List <AccountModel> query = conn.Query <AccountModel>(SQLs.ToString(), new { Account_Account = Acc }) .AsList(); if (query.Count == 0) { throw new LogInException("202", "查無該帳號"); } if (query.Count > 1) { throw new LogInException("202", "帳號異常,重複註冊"); } #region 重複嘗試失敗 #endregion 重複嘗試失敗 var User = query[0]; if (!EncodeHelper.Encode(EncodeEnum.SHA1, Pass).Equals(User.Account_Password)) { throw new LogInException("202", "密碼錯誤"); } result = User; } return(result); }
public IActionResult Encode() { ResponseModel Result = new ResponseModel(); try{ var TxtToEncode = Request.Form["txt"]; if (!string.IsNullOrWhiteSpace(TxtToEncode)) { object EncodeType = Enum.Parse(typeof(EncodeEnum), Request.Form["CMD"].ToString()); TxtToEncode = EncodeHelper.Encode(EncodeType, TxtToEncode); } if (!string.IsNullOrWhiteSpace(TxtToEncode)) { Result.HttpStatus = "1"; Result.Message = TxtToEncode; } } catch (Exception ex) { Result.HttpStatus = "0"; Result.Message = ex.Message; } return(Json(Result)); }
public void EncodeSuccess() { string sample = "27-3A-0C-7B-D3-C6-79-BA-9A-6F-5D-99-07-8E-36-E8-5D-02-B9-52"; Assert.Equal(sample, EncodeHelper.Encode(EncodeEnum.SHA1, "222222")); }
public void EncodeSuccessSHA256() { string sample = "4C-C8-F4-D6-09-B7-17-35-67-01-C5-7A-03-E7-37-E5-AC-8F-E8-85-DA-8C-71-63-D3-DE-47-E0-18-49-C6-35"; Assert.Equal(sample, EncodeHelper.Encode(EncodeEnum.SHA256, "222222")); }