/// <summary> /// Gets the account for the specified key. /// </summary> /// <returns>The account with Item1 as username and Item2 as password.</returns> /// <param name="service">ISecureStorageService instance.</param> /// <param name="key">Key.</param> public static Tuple <string, string> GetAccount(this ISecureStorageService service, string key) { var record = service.Get(key); if (string.IsNullOrWhiteSpace(record)) { return(null); } var account = record.Split(new char[] { ';' }, 2); if (int.TryParse(account[0], out int usernameLength)) { var credentials = account.ElementAtOrDefault(1); if (string.IsNullOrWhiteSpace(credentials)) { return(null); } var username = credentials.Substring(0, usernameLength); var password = credentials.Substring(usernameLength, credentials.Length - usernameLength); return(new Tuple <string, string>(username, password)); } return(null); }
public async Task <bool> AuthenticateUser(string username, string password) { var user = await _secureStorageService.Get <UserAccountModel>(username); if (user is null) { throw new UserAccounException("The account does not exist."); } if (user.Password != password) { throw new UserAccounException("Password incorrect."); } return(true); }