public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); // Create the two factor secret key var profile = MvcTFAProfile.GetProfile(model.UserName); profile.SecretKey = Base32Encoder.ToBase32String(GoogleAuthenticator.GenerateSecretKey()); return(RedirectToAction("Index", "Home")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }
public void ToBase32StringShouldReturnBase32EncodedString() { // Arrange const string data = "test string"; // EQ: ORSXG5BAON2HE2LOM4 / orsxg5baon2he2lom4 as Base32 var bytes = Encoding.UTF8.GetBytes(data); // Act var result = Base32Encoder.ToBase32String(bytes); // Assert var viewResult = Assert.IsType <string>(result); Assert.Equal("ORSXG5BAON2HE2LOM4", viewResult); Assert.Equal("orsxg5baon2he2lom4", viewResult, true); }
public void WhenDataIsEncodedTheResultIsCorrect(string input, string base32String) { Assert.Equal(base32String, Base32Encoder.ToBase32String(Encoding.ASCII.GetBytes(input))); }