public LoginReponse Encode(PassCode passCode, int expired = 1) { var symmetricKey = Convert.FromBase64String(Secret); var tokenHandler = new JwtSecurityTokenHandler(); var now = DateTime.UtcNow; var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim("Id", passCode.Id.ToString()), new Claim("ServiceId", passCode.ServiceId.ToString()) }), Expires = now.AddHours(Convert.ToInt32(expired)), SigningCredentials = new SigningCredentials( new SymmetricSecurityKey(symmetricKey), SecurityAlgorithms.HmacSha256Signature) }; var stoken = tokenHandler.CreateToken(tokenDescriptor); var token = tokenHandler.WriteToken(stoken); var refreshToken = generateRefreshToken(); return(new LoginReponse { Token = token, RefreshToken = refreshToken, }); }
public void LeftMovesCorrectly(int startkey, int expected) { PassCode p = new PassCode(); var result = p.GetKeyFromCode("L", startkey); Assert.Equal(expected, result); }
public void DownMovesCorrectly(int startkey, int expected) { PassCode p = new PassCode(); var result = p.GetKeyFromCode("D", startkey); Assert.Equal(result, expected); }
/// <summary> /// Changes the pass code. /// </summary> /// <param name="newPassCode">The new pass code.</param> /// <returns>Returns true if operation was successful.</returns> public Card ChangePassCode(int newPassCode) { ImageUrl.Replace(PassCode.ToString(), newPassCode.ToString()); SmallImageUrl.Replace(PassCode.ToString(), newPassCode.ToString()); PassCode = newPassCode; return(this); }
public List<byte> PassIndex(PassCode[] xIn) { List<byte> xReturn = new List<byte>(); for (int i = 0; i < xIn.Length; i++) { switch (xIn[i]) { case PassCode.UpDPad: xReturn.Add(1); break; case PassCode.DownDPad: xReturn.Add(2); break; case PassCode.LeftDPad: xReturn.Add(3); break; case PassCode.RightDPad: xReturn.Add(4); break; case PassCode.X: xReturn.Add(5); break; case PassCode.Y: xReturn.Add(6); break; case PassCode.LTrigger: xReturn.Add(7); break; case PassCode.RTrigger: xReturn.Add(8); break; case PassCode.LBumper: xReturn.Add(9); break; case PassCode.RBumper: xReturn.Add(10); break; default: xReturn.Add(0); break; } } return xReturn; }
public async Task <IActionResult> ForgotPassword(PassCode details, string returnUrl) { //await userManager.FindByEmailAsync(details.Email); //return View("PasswordCode"); if (ModelState.IsValid) { AppUser user = await userManager.FindByNameAsync(details.Email); if (user == null) { ModelState.AddModelError("", "The user either does not exist or is not confirmed."); } else { SmtpClient SmtpClient = new SmtpClient("smtp.gmail.com"); SmtpClient.UseDefaultCredentials = false; SmtpClient.Credentials = new NetworkCredential("*****@*****.**", "wctcJeff!"); SmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; SmtpClient.EnableSsl = true; MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress("*****@*****.**"); mailMessage.To.Add(details.Email); //mailMessage.Body = "jhoiji"; var token = await userManager.GeneratePasswordResetTokenAsync(user); mailMessage.Body = "Follow this instruction to have your email/userId reset .\n Click the link to choose a new password with " + "the given token. http://finalnorthwind.azurewebsites.net/Account/NewPassword" + " " + " \n copy and paste the token in the required field \n" + " Token =" + " " + token; //<a href="NewPassword">New Password</a> mailMessage.Subject = "Requested Reset Password"; SmtpClient.Send(mailMessage); //if (user != null) //{ //await signInManager.SignOutAsync();B // string code = await userManager.GeneratePasswordResetTokenAsync(user); // AppUser callbackUrl = Url.Action("NewPassword", "Account", new { v = user.Id = user.Id, code = code }, protocol: Request.Url.Scheme); // await userManager.SendEmailAsync(user.Email, "Reset Password", //"Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">NewPassword</a>"); // return View("PasswordCode"); return(View("PasswordCode")); } } return(View("ForgotPassword")); }
public IActionResult NewRandom(PassCode newCode) { if (HttpContext.Session.GetInt32("count") == null) { HttpContext.Session.SetInt32("count", 1); ViewBag.Count = 1; } else { int myCount = (int)HttpContext.Session.GetInt32("count"); myCount++; HttpContext.Session.SetInt32("count", myCount); ViewBag.Count = myCount; } HttpContext.Session.SetString("Code", newCode.RandomString); string myString = HttpContext.Session.GetString("Code"); return(View("Index", myString)); }
public void MyCodeYieldsProvidedSolution() { List <string> inputs = new List <string>() { "ULL", "RRDDD", "LURDL", "UUUUD" }; PassCode pee = new PassCode(); List <int> entryCode = new List <int>(); var currentKey = 5; foreach (var s in inputs) { currentKey = (pee.GetKeyFromCode(s, currentKey)); entryCode.Add(currentKey); } Assert.Equal(entryCode[0], 1); //1985 Assert.Equal(entryCode[1], 9); Assert.Equal(entryCode[2], 8); Assert.Equal(entryCode[3], 5); }
public async Task <IHttpActionResult> GetPasscode(string email) { ApplicationUser user = await AppUserManager.FindByEmailAsync(email); if (user == null) { return(BadRequest()); } string code = PassCode.GeneratePresharedKey(); user.PasscodeHash = code; user.LockoutEndDateUtc = DateTime.UtcNow.AddMinutes(30); IdentityResult userResult = await this.AppUserManager.UpdateAsync(user); if (!userResult.Succeeded) { return(GetErrorResult(userResult)); } await this.AppUserManager.SendEmailAsync(user.Id, "Login Passcode", code); return(Ok()); }
public Boolean Post([FromBody] PassCode pass) { return(Password == pass.Pass); }
/// <summary> /// Sets the pass code /// </summary> /// <param name="xPass"></param> /// <returns></returns> public bool SetPassCode(PassCode[] xPass) { if (xPass == null || xPass.Length != 4 || xPass.Contains(PassCode.Null)) return false; DJsIO xTemp = GetDecrypt(); if (xTemp == null) return false; xTemp.Position = 0x38; for (int i = 0; i < 4; i++) xTemp.Write((byte)xPass[0]); return xEncrypt(ref xTemp); }