public static String GetUserCode(byte[] privateKey) { //create new otp auth with user private key GoogleTOTP googleTOTP = new GoogleTOTP(privateKey); //get otp auth return(googleTOTP.GeneratePin()); }
partial void BtnActivateDAuth_TouchUpInside(UIButton sender) { if (String.IsNullOrEmpty(tfCodeField.Text)) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, MSGBank.ERROR_FILL_ALL_FIELDS); return; } if (googleTOTP.GeneratePin().ToLower() != tfCodeField.Text.ToLower()) { BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, "Code erroné !"); return; } ServerPacketConfirmation serverPacketConfirmation = ServerHelper.EnableUserDAuth(Application.ActualUser, googleTOTP.getPrivateKey()); //if success if (serverPacketConfirmation.ActionSuccess) { Application.ActualUserPrivateKey = googleTOTP.getPrivateKey(); MessageBox.ShowOK("Double authentification", "La double authentification a bien été activée.", this, delegate { this.NavigationController.PopToRootViewController(true); }); } else { //get the good error message String errorMessage = string.Empty; switch (serverPacketConfirmation.NetworkError) { case NetworkError.SERVER_UNAVAILABLE: errorMessage = MSGBank.ERROR_NO_SERVER; break; default: errorMessage = $"Impossible d'activer la double authentification."; break; } BarHelper.DisplayErrorBar(uivMainView, MSGBank.ERROR_TITLE, errorMessage); } }