public async Task <HashModel> GetHashByKeyAsync(string key) { try { var data = await _cache.GetAsync(key); if (data != null) { var dataAsString = Encoding.UTF8.GetString(data); HashModel returnData = new HashModel(); returnData.key = key; returnData.fields = JsonConvert.DeserializeObject <Dictionary <string, string> >(dataAsString); _logger.LogInformation($"Retrieved Key {key} from the cache. {DateTime.Now}"); return(returnData); } else { return(new HashModel()); } } catch (Exception ex) { _logger.LogError(ex, $"Error retrieving key {key} from the cache. {DateTime.Now}"); return(new HashModel()); throw ex; } }
public HttpResponseMessage Login(LoginModel loginModel) { try { var user = DBContext.Employee.FirstOrDefault(x => x.UserName == loginModel.Username); if (user != null) { var hash = new HashModel() { Password = loginModel.Password, Salt = user.Salt }; var hashedPassword = PasswordHashHelper.PasswordHasher(hash); if (hashedPassword == user.Pword) { return(new HttpResponseMessage(HttpStatusCode.OK)); } } } catch (Exception) { throw; } return(new HttpResponseMessage(HttpStatusCode.Forbidden)); }
private IActionResult VoteWhitelistRemoveHashMember(HashModel request, bool whitelist) { Guard.NotNull(request, nameof(request)); if (!this.ModelState.IsValid) { return(ModelStateErrors.BuildErrorResponse(this.ModelState)); } if (!this.fedManager.IsFederationMember) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Only federation members can vote", string.Empty)); } try { var hash = new uint256(request.Hash); this.votingManager.ScheduleVote(new VotingData() { Key = whitelist ? VoteKey.WhitelistHash : VoteKey.RemoveHash, Data = hash.ToBytes() }); return(this.Ok()); } catch (Exception e) { this.logger.LogError("Exception occurred: {0}", e.ToString()); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "There was a problem executing a command.", e.ToString())); } }
/// <summary> /// Votes to add a hash to the whitelist. /// </summary> /// <param name="request"></param> /// <returns></returns> public void VoteWhitelistHash(HashModel request) { var path = "/api/DefaultVoting/schedulevote-whitelisthash"; path = path.Replace("{format}", "json"); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(request); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling VoteWhitelistHash: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling VoteWhitelistHash: " + response.ErrorMessage, response.ErrorMessage); } return; }
public async Task <IActionResult> Index([FromBody] HashModel request) { if (string.IsNullOrEmpty(request.Login) || string.IsNullOrEmpty(request.Password)) { return(BadRequest()); } return(Ok(await GetHashValue(request))); }
public IActionResult Sync([FromBody] HashModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var block = this.chain.GetBlock(uint256.Parse(model.Hash)); this.walletSyncManager.SyncFromHeight(block.Height); return(this.Ok()); }
private static async Task <HashModel> GetHashValue(HashModel request) { var response = request; var json = JsonConvert.SerializeObject(request); var data = new StringContent(json, Encoding.UTF8, "application/json"); var functionResponse = await Client.PostAsync("http://localhost:7071/api/Function1", data); response.Hash_Value = await functionResponse.Content.ReadAsStringAsync(); return(response); }
public static string PasswordHasher(HashModel hash) { var cArray = hash.Salt.ToCharArray(); Array.Reverse(cArray); string saltAndPassword = String.Concat(hash.Password, new string(cArray)); string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile(saltAndPassword, "sha1"); return(hashedPwd); }
public async Task <ActionResult> SetHash([FromBody] HashModel setHashObject) { var response = await _cacheManager.SetHashAsync(setHashObject); if (response == true) { var resp = await _cacheManager.SetHashAsync(setHashObject); return(Ok()); } return(NotFound()); }
/// <summary> /// Starts sending block to the wallet for synchronisation. /// This is for demo and testing use only. /// </summary> /// <param name="model">The hash of the block from which to start syncing.</param> /// <returns></returns> public void Sync(HashModel model) { //if (!this.ModelState.IsValid) //{ // return BuildErrorResponse(this.ModelState); //} ChainedBlock block = this.chain.GetBlock(uint256.Parse(model.Hash)); if (block == null) { throw new Exception("Block with hash {model.Hash} was not found on the blockchain."); } this.walletSyncManager.SyncFromHeight(block.Height); }
public async Task <IActionResult> Sync([FromBody] HashModel model, CancellationToken cancellationToken = default(CancellationToken)) { return(await this.ExecuteAsAsync(model, cancellationToken, (req, token) => { ChainedHeader block = this.chainIndexer.GetHeader(uint256.Parse(model.Hash)); if (block == null) { return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, $"Block with hash {model.Hash} was not found on the blockchain.", string.Empty); } this.walletSyncManager.SyncFromHeight(block.Height); return this.Ok(); })); }
public IActionResult Sync([FromBody] HashModel model) { if (!this.ModelState.IsValid) { return(BuildErrorResponse(this.ModelState)); } ChainedBlock block = this.chain.GetBlock(uint256.Parse(model.Hash)); if (block == null) { return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, $"Block with hash {model.Hash} was not found on the blockchain.", string.Empty)); } this.walletSyncManager.SyncFromHeight(block.Height); return(this.Ok()); }
public override void SetRangeInHash(string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs) { foreach (var keyValuePair in keyValuePairs) { var fetchedHash = _storage.ObjectRepository .Set <HashModel>() .FirstOrDefault(v => v.Key == key && v.Field == keyValuePair.Key); if (fetchedHash == null) { fetchedHash = new HashModel(key, keyValuePair.Key); _storage.ObjectRepository.Add(fetchedHash); } fetchedHash.Value = keyValuePair.Value; } }
public async Task <bool> SetHashAsync(HashModel hashData) { try { var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(hashData.fields)); await _cache.SetAsync(hashData.key, data); _logger.LogInformation($"Added Key {hashData.key} to the cache. {DateTime.Now}"); } catch (Exception ex) { _logger.LogError(ex, $"Error saving key {hashData.key} to the cache. {DateTime.Now}"); return(false); throw ex; } return(true); }
public async Task CanVoteToWhitelistAndRemoveHashesAsync() { int maxReorg = (int)this.network.Consensus.MaxReorgLength; Assert.Empty(this.node1.FullNode.NodeService <IWhitelistedHashesRepository>().GetHashes()); TestHelper.Connect(this.node1, this.node2); await this.node1.MineBlocksAsync(1); var model = new HashModel() { Hash = Hashes.Hash256(RandomUtils.GetUInt64().ToBytes()).ToString() }; // Node 1 votes to add hash this.node1.FullNode.NodeService <DefaultVotingController>().VoteWhitelistHash(model); await this.node1.MineBlocksAsync(1); CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2); // Node 2 votes to add hash this.node2.FullNode.NodeService <DefaultVotingController>().VoteWhitelistHash(model); await this.node2.MineBlocksAsync(maxReorg + 2); CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2); Assert.Single(this.node1.FullNode.NodeService <IWhitelistedHashesRepository>().GetHashes()); // Node 1 votes to remove hash this.node1.FullNode.NodeService <DefaultVotingController>().VoteRemoveHash(model); await this.node1.MineBlocksAsync(1); CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2); // Node 2 votes to remove hash this.node2.FullNode.NodeService <DefaultVotingController>().VoteRemoveHash(model); await this.node2.MineBlocksAsync(maxReorg + 2); CoreNodePoAExtensions.WaitTillSynced(this.node1, this.node2); Assert.Empty(this.node1.FullNode.NodeService <IWhitelistedHashesRepository>().GetHashes()); }
public HashController(HashModel hashModel, HashView hashView) { this.hashModel = hashModel; this.hashView = hashView; }
public IActionResult VoteRemoveHash([FromBody] HashModel request) { return(this.VoteWhitelistRemoveHashMember(request, false)); }