public static bool TryToRegister(TcpAccountInfo accountInfo, bool accepted) { DataSet data = DBSelect("[교사 ID]", "[교사 목록]", $"[교사 ID]={accountInfo.ID.ToSQLString()}", null); if (data.Tables[0].Rows.Count != 0) { return(false); } DBInsert("[교사 목록]", accountInfo.ID.ToSQLString(), PasswordHashManager.HashPassword(accountInfo.Password).ToSQLString(), accountInfo.Name.ToSQLString(), accountInfo.Type.ToSQLString(), accepted ? "True" : "False"); return(true); }
public static TcpLoginResult MatchLoginInfo(TcpLoginInfo info) { DataSet data = DBSelect("*", "[교사 목록]", $"[교사 ID]={info.ID.ToSQLString()}", null); DataTable mainTable = data.Tables[0]; int rowsCount = mainTable.Rows.Count; if (rowsCount == 0) { return(new TcpLoginResult("", "", "", false, false, false)); } else if (rowsCount > 1) { throw new InvalidOperationException("데이터베이스에 같은 교사 ID가 여러개 있습니다."); } string id = info.ID; string name = mainTable.Rows[0]["성명"].ToString(); string type = mainTable.Rows[0]["계정 구분"].ToString(); string correctPWHash = mainTable.Rows[0]["PW 해시"].ToString(); bool pwCorrect = PasswordHashManager.ValidatePassword(info.Password, correctPWHash); bool accepted = (bool)mainTable.Rows[0]["가입 허가 여부"]; return(new TcpLoginResult(id, name, type, true, pwCorrect, accepted)); }