Skip to content

Instantly share code, notes, and snippets.

@Veretax
Created August 25, 2019 17:42
Show Gist options
  • Save Veretax/e84734391baadb8a96b9d7c52b439e6e to your computer and use it in GitHub Desktop.
Save Veretax/e84734391baadb8a96b9d7c52b439e6e to your computer and use it in GitHub Desktop.
How to create debugger + app.config bypass for login credentials
add this key to app.confing <app settings>:
<add key="testUserKey" value="{substitute your nvarchar ID from the database}" />
// add the following usings
using System.Configuration;
using System.Diagnostics;
// Update the two methods below:
// Update Can Login so Login buttin is enabled by default if Debugger is attached
public bool CanLogIn
{
get
{
if (Debugger.IsAttached && ConfigurationManager.AppSettings["testUserKey"] != null)
{
return true;
}
else
{
bool output = false;
if (UserName?.Length > 0 && Password?.Length > 0)
{
output = true;
}
return output;
}
}
}
// Update Login so if debugger attached and bypass key is detected, can bypass authentication
public async Task LogIn()
{
try
{
ErrorMessage = "";
if (Debugger.IsAttached && ConfigurationManager.AppSettings["testUserKey"] != null)
{
var access_token = ConfigurationManager.AppSettings["testUserKey"];
// Capture more information about the user
await _apiHelper.GetLoggedInUserInfo(access_token);
}
else
{
// If not in debugging mode, and appsetting key not there (both have to be true to bypass)
// So only process normal login
var result = await _apiHelper.Authenticate(UserName, Password);
// Capture more information about the user
await _apiHelper.GetLoggedInUserInfo(result.Access_Token);
}
_events.PublishOnUIThread(new LogOnEvent());
}
catch (Exception ex)
{
ErrorMessage = ex.Message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment