public string SubmitUserData([FromBody] string args) { ResetTimeout(); string[] separatedArgs = args.Split(','); if (separatedArgs.Length < 2) { throw (new Exception("Illegal number of arguments")); } bool isAdmin = SUP_Library.DatabaseConnection.isAdmin(separatedArgs[4]); if (!isAdmin) { return(JsonConvert.SerializeObject(false)); } var username = separatedArgs[0]; var password = separatedArgs[1]; ReadOnlySpan <byte> pkBytes = new ReadOnlySpan <byte>(SUP_Library.DatabaseConnection.getPrivateKey()); RSACryptoServiceProvider p = new RSACryptoServiceProvider(); p.ImportRSAPrivateKey(new ReadOnlySpan <byte>(SUP_Library.DatabaseConnection.getPrivateKey()), out int bytesRead); string decryptedPassword = CustomRSA.Decrypt(p, password); var accountType = separatedArgs[2]; var office = separatedArgs[3]; var result = SUP_Library.DatabaseConnection.addAccount(username, decryptedPassword, accountType[0], office); var json = JsonConvert.SerializeObject(result); return(json); }
public string AuthenticateUser([FromBody] string args) { try { string[] separatedArgs = args.Split(','); if (separatedArgs.Length != 2) { throw (new Exception("Oopsie")); } var userName = separatedArgs[0]; var password = separatedArgs[1]; ReadOnlySpan <byte> pkBytes = new ReadOnlySpan <byte>(SUP_Library.DatabaseConnection.getPrivateKey()); RSACryptoServiceProvider p = new RSACryptoServiceProvider(); p.ImportRSAPrivateKey(new ReadOnlySpan <byte>(SUP_Library.DatabaseConnection.getPrivateKey()), out int bytesRead); string decryptedPassword = CustomRSA.Decrypt(p, password); //TODO: HASH HERE var LoginSuccessful = DatabaseConnection.verifiedLogIn(userName, decryptedPassword); if (LoginSuccessful == "success") { //TODO: STORE SESSION HERE TempData["UserID"] = userName; TempData["LoginDate"] = DateTime.Now.ToShortDateString(); TempData["LoginTime"] = DateTime.Now.ToShortTimeString(); } // if searching for active clients only, remove inactive clients. var json = JsonConvert.SerializeObject(LoginSuccessful); return(json); } catch (Exception e) { throw e; } }