public FunctionAttr(string fileRoutePath, string functlp) { string fromatFunctlp = Regex.Replace(functlp, @"[\(\)]", " "); fromatFunctlp = Regex.Replace(fromatFunctlp, @"\,", ""); fromatFunctlp = Regex.Replace(fromatFunctlp, @"^\s*", ""); fromatFunctlp = Regex.Replace(fromatFunctlp, @"\s*$", ""); string[] funcTlpList = fromatFunctlp.Split(" "); if (funcTlpList.Length < 4 && funcTlpList.Length % 2 == 0) { throw new System.Exception("parse function arguments is failed, " + functlp); } m_retValue = new FunctionArg(funcTlpList[0], "ret" + funcTlpList[0]); m_funcName = funcTlpList[1]; m_funcHash = (size_t)HashEncoder.Hash(System.Text.Encoding.UTF8.GetBytes(fileRoutePath + m_funcName)); for (int i = 2; i < funcTlpList.Length; i += 2) { m_funcArgMap = new FunctionArg(funcTlpList[i], funcTlpList[i + 1]); } }
public void EncodeAndDecodeNullHash() { HashEncoder encoder = new HashEncoder(); byte[] bytes = encoder.Encode(null); Assert.IsNotNull(bytes); Assert.AreNotEqual(0, bytes.Length); Hash result = encoder.Decode(bytes); Assert.IsNull(result); }
public static void HashEncoder() { // Arrange var value = RandomHelper.NextSentence(g_random, 20); var encoder = new HashEncoder(new HashAlgorithmProvider <SHA1CryptoServiceProvider>(), new TextEncoder(Encoding.UTF8)); // Act var result = encoder.GetBytes(value); // Assert var expected = new SHA1CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(value)); Assert.Equal(expected, result); }
public async Task <IActionResult> LoginQrCode(string userId, string returnUrl, string pincodeInput) { var context = await _interaction.GetAuthorizationContextAsync(returnUrl); var user = await _userManager.FindByIdAsync(userId); if (user.Pincode != HashEncoder.GetHashString(pincodeInput)) { return(await QrCodeError(returnUrl)); } await _signInManager.SignInAsync(user, true); await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName)); if (context != null) { if (await _clientStore.IsPkceClientAsync(context.ClientId)) { return(View("Redirect", new RedirectViewModel { RedirectUrl = returnUrl })); } // we can trust model.ReturnUrl since GetAuthorizationContextAsync returned non-null return(Redirect(returnUrl)); } // request for a local page if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } return(string.IsNullOrEmpty(returnUrl) ? Redirect("~/") : null); }
public static async Task Initialize(ApplicationDbContext context, UserManager <ApplicationUser> userManager, RoleManager <ApplicationRole> roleManager) { context.Database.EnsureCreated(); var employerRole = "Employer"; var personRole = "Person"; var password = "******"; if (await roleManager.FindByNameAsync(employerRole) == null) { await roleManager.CreateAsync(new ApplicationRole(employerRole)); } if (await roleManager.FindByNameAsync(personRole) == null) { await roleManager.CreateAsync(new ApplicationRole(personRole)); } if (await userManager.FindByNameAsync("SiebeCorstjens") == null) { var user = new ApplicationUser { Id = "1", UserName = "******", FirstName = "Siebe", LastName = "Corstjens", Email = "*****@*****.**", PhoneNumber = "0490634251", QrCode = Guid.NewGuid(), Pincode = HashEncoder.GetHashString("1000"), }; var result = await userManager.CreateAsync(user); if (result.Succeeded) { await userManager.AddPasswordAsync(user, password); await userManager.AddToRoleAsync(user, employerRole); } } if (await userManager.FindByNameAsync("LiesbethVandevenne") == null) { var user = new ApplicationUser { Id = "2", UserName = "******", FirstName = "Liesbeth", LastName = "Vandevenne", Email = "*****@*****.**", PhoneNumber = "0478812257", QrCode = Guid.NewGuid(), Pincode = HashEncoder.GetHashString("1000"), }; var result = await userManager.CreateAsync(user); if (result.Succeeded) { await userManager.AddPasswordAsync(user, password); await userManager.AddToRoleAsync(user, employerRole); } } if (await userManager.FindByNameAsync("LornaDeVroom") == null) { var user = new ApplicationUser { Id = "3", UserName = "******", FirstName = "Lorna", LastName = "De Vroom", Email = "*****@*****.**", PhoneNumber = "0474267406", QrCode = Guid.NewGuid(), Pincode = HashEncoder.GetHashString("9999"), }; var result = await userManager.CreateAsync(user); if (result.Succeeded) { await userManager.AddPasswordAsync(user, password); await userManager.AddToRoleAsync(user, personRole); } } if (await userManager.FindByNameAsync("MyriamDekens") == null) { var user = new ApplicationUser { Id = "4", UserName = "******", FirstName = "Myriam", LastName = "Dekens", Email = "*****@*****.**", PhoneNumber = "0473576611", QrCode = Guid.NewGuid(), Pincode = HashEncoder.GetHashString("9999"), }; var result = await userManager.CreateAsync(user); if (result.Succeeded) { await userManager.AddPasswordAsync(user, password); await userManager.AddToRoleAsync(user, personRole); } } }