public async Task IncrementHotp(int position) { if (Authenticators.ElementAtOrDefault(position) == null) { return; } var info = Authenticators[position]; var auth = GetAuthenticator(info); if (auth.Type != OtpType.Hotp) { return; } var secret = Base32.Decode(auth.Secret); var hotp = new Hotp(secret, auth.Algorithm); auth.Counter++; auth.Code = hotp.ComputeHotp(auth.Counter); auth.TimeRenew = DateTime.Now.AddSeconds(10); Authenticators[position] = auth; await _connection.UpdateAsync(auth); }
public async Task IncrementCounter(int position) { var auth = Authenticators.ElementAtOrDefault(position); if (auth == null) { return; } auth.Counter++; await _connection.UpdateAsync(auth); }
public async Task Rename(int position, string issuer, string username) { var auth = Authenticators.ElementAtOrDefault(position); if (auth == null) { return; } auth.Issuer = issuer; auth.Username = username; await _connection.UpdateAsync(auth); }
public async Task Rename(int position, string issuer, string username) { if (Authenticators.ElementAtOrDefault(position) == null) { return; } var info = Authenticators[position]; var auth = GetAuthenticator(info); auth.Issuer = issuer.Trim().Truncate(32); auth.Username = username.Trim().Truncate(32); await _connection.UpdateAsync(auth); }
public async Task Delete(int position) { var auth = Authenticators.ElementAtOrDefault(position); if (auth == null) { return; } await _connection.DeleteAsync <Authenticator>(auth.Secret); Authenticators.Remove(auth); _all.Remove(auth); const string sql = "DELETE FROM authenticatorcategory WHERE authenticatorSecret = ?"; await _connection.ExecuteAsync(sql, auth.Secret); }
public async Task Delete(int position) { if (Authenticators.ElementAtOrDefault(position) == null) { return; } var info = Authenticators[position]; var auth = GetAuthenticator(info); await _connection.DeleteAsync <Authenticator>(auth.Secret); Authenticators.Remove(info); _all.Remove(auth); var sql = "DELETE FROM authenticatorcategory WHERE authenticatorSecret = ?"; object[] args = { auth.Secret }; await _connection.ExecuteAsync(sql, args); }
public Authenticator Get(int position) { if (Authenticators.ElementAtOrDefault(position) == null) { return(null); } var info = Authenticators[position]; var auth = GetAuthenticator(info); if (auth.Type == OtpType.Totp && auth.TimeRenew <= DateTime.Now) { var secret = Base32.Decode(auth.Secret); var totp = new Totp(secret, auth.Period, auth.Algorithm, auth.Digits); auth.Code = totp.ComputeTotp(); auth.TimeRenew = DateTime.Now.AddSeconds(totp.RemainingSeconds()); } return(auth); }