private void InitLogin() { Excel2007Addin.Settings settings = Excel2007Addin.Settings.Default; this._login = new Login(_user); _login.authSuccessful += new Login.AuthSuccessful(User_Successful_Login); _login.logOut += new Login.Logout(User_Logout); _login.Username = settings.Username; _login.Password = DataProtectionHelper.UnProtect(settings.Password); _login.RememberPassword = settings.RememberPassword; if (_login.ShowDialog().GetValueOrDefault(false)) { settings.RememberPassword = _login.RememberPassword; settings.Username = _login.Username; if (_login.RememberPassword) { settings.Password = DataProtectionHelper.Protect(_login.Password); } else { settings.Password = DataProtectionHelper.Protect(""); } settings.Save(); } }
public NoteController(IDataProtectionProvider provider, ApiService apiService, EncryptionService encryptionService, ICacheService cacheService) { dataProtectionHelper = new DataProtectionHelper(provider); _apiService = apiService; _encryptionService = encryptionService; _cacheService = cacheService; }
public PhoneController(IDataProtectionProvider provider, ApiService apiService, EncryptionService encryptionService, ICacheService cacheService, IConfiguration config) { dataProtectionHelper = new DataProtectionHelper(provider); _apiService = apiService; _encryptionService = encryptionService; _cacheService = cacheService; _config = config; }
public void StorePassword(string filePath) { if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(Password)) { DataProtectionHelper.WriteProtectedBytesToFile(filePath, Password); Password = ""; } }
public UserService(IUnitOfWork unitOfWork, IHttpContextAccessor httpContextAccessor, IDataProtectionProvider provider, IEmailSender emailSender, IConfiguration config, EncryptionService encryptService) { _unitOfWork = unitOfWork; _httpContextAccessor = httpContextAccessor; _emailSender = emailSender; dataProtectionHelper = new DataProtectionHelper(provider); _config = config; _encryptService = encryptService; }
public void ReadPassword(string filePath) { // if autologin is set, load the password for this user if (!string.IsNullOrEmpty(filePath)) { // method below handles checking for file existance Password = DataProtectionHelper.ReadUnprotectedBytesFromProtectedFile(filePath); } }
public LoginDataController(IDataProtectionProvider provider, ApiService apiService, EncryptionService encryptionService, ICacheService cacheService, IConfiguration config, NotificationService notify) { dataProtectionHelper = new DataProtectionHelper(provider); _apiService = apiService; _encryptionService = encryptionService; _cacheService = cacheService; _config = config; _notify = notify; }
public AuthController(IDataProtectionProvider provider, ApiService apiService, JwtHelper jwtHelper, LogInHandler logInHandler, IConfiguration config, EncryptionService encryptionService, NotificationService notify) { _apiService = apiService; dataProtectionHelper = new DataProtectionHelper(provider); cookieHandler = new CookieHandler(new HttpContextAccessor(), provider, config); _jwtHelper = jwtHelper; _logInHandler = logInHandler; _encryptionService = encryptionService; _notify = notify; }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Provide encrypted password value from the config file."); return; } DataProtectionHelper helper = new DataProtectionHelper(); Console.WriteLine(helper.Decrypt(args[0])); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDataProtection(); services.AddCors(options => { options.AddPolicy(AllowAllOriginsPolicy, builder => builder .WithOrigins("http://itlec.com") .SetIsOriginAllowed((host) => true) .AllowAnyMethod() .AllowAnyHeader() ); }); services.AddControllers(); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "ITLec API", Description = "A simple example ASP.NET Core Web API", TermsOfService = new Uri("https://ITLec.com/terms"), Contact = new OpenApiContact { Name = "Rasheed Gomaa", Email = string.Empty, Url = new Uri("https://twitter.com/spboyer"), }, License = new OpenApiLicense { Name = "Use under LICX", Url = new Uri("https://ITLec.com/license"), } }); //https://stackoverflow.com/questions/57796805/swashbuckle-swagger-asp-net-core-pass-api-key-as-default-header-value-in-request c.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme { Description = "Enter your Api Key below:", Name = ApiKeyMiddleware.API_KEY, In = ParameterLocation.Query, Type = SecuritySchemeType.ApiKey }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "ApiKey" }, }, new List <string>() } }); }); services.ConfigureSwaggerGen(options => { options.OperationFilter <AuthorizationHeaderParameterOperationFilter>(); }); services.AddSwaggerGenNewtonsoftSupport(); //services.Configure<RouteOptions>(options => // options.ConstraintMap.Add("validAccount", typeof(CustomValidationConstraint))); services.Configure <RouteOptions>(options => options.ConstraintMap.Add("validIP", typeof(CustomValidationConstraint))); services.Configure <RouteOptions>(options => options.ConstraintMap.Add("enum", typeof(EnumerationConstraint))); ////https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-3.1 //services.Configure<ForwardedHeadersOptions>(options => //{ // options.ForwardedHeaders = // ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; //}); //Add header: Authorization= bearer JWT which is generated from api/auth/token services.AddAuthentication(o => { o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.TokenValidationParameters = new TokenValidationParameters { IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is my custom Secret key for authnetication")), ValidateIssuer = true, ValidateAudience = true, ValidIssuer = "Tokens:Issuer", ValidAudience = "Tokens:Audience" }; }); var serviceProvider = services.BuildServiceProvider(); DataProtectionHelper = ActivatorUtilities.CreateInstance <DataProtectionHelper>(serviceProvider); }
private void SettingsButton_Click(object sender, RibbonControlEventArgs e) { Excel2007Addin.Settings settings = Excel2007Addin.Settings.Default; SettingsDialog settingsdlg = new SettingsDialog(); settingsdlg.AutoEscapeFilter = settings.AutoEscapeFilter; settingsdlg.UseProxy = settings.UseProxy; settingsdlg.ProxyAddress = settings.ProxyAddress; settingsdlg.ProxyPort = settings.ProxyPort; settingsdlg.ProxyUsername = settings.ProxyUsername; settingsdlg.ProxyPassword = DataProtectionHelper.UnProtect(settings.ProxyPassword); settingsdlg.RequestTimeout = settings.RequestTimeout; settingsdlg.CellFormatting = (CellFormattingEnum)settings.CellFormatting; if (settingsdlg.ShowDialog().GetValueOrDefault(false)) { // Update metrics xml? if (!string.IsNullOrEmpty(settingsdlg.MetricsFileName)) { System.Xml.XmlDocument doc = new System.Xml.XmlDataDocument(); try { doc.Load(XmlReader.Create(settingsdlg.MetricsFileName, new XmlReaderSettings() { Schemas = Analytics.Data.Validation.XmlValidator.LoadSchema("metrics.xsd"), ValidationType = ValidationType.Schema })); settings.Metrics = doc; } catch (Exception) { MessageBox.Show("Error parsing metrics xml. No metrics updated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Update dimensions xml? if (!string.IsNullOrEmpty(settingsdlg.DimensionsFileName)) { System.Xml.XmlDocument doc = new System.Xml.XmlDataDocument(); try { doc.Load(XmlReader.Create(settingsdlg.DimensionsFileName, new XmlReaderSettings() { Schemas = Analytics.Data.Validation.XmlValidator.LoadSchema("dimensions.xsd"), ValidationType = ValidationType.Schema })); settings.Dimensions = doc; } catch (Exception) { MessageBox.Show("Error parsing dimension xml. No dimensions updated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } settings.AutoEscapeFilter = settingsdlg.AutoEscapeFilter; settings.UseProxy = settingsdlg.UseProxy; settings.ProxyAddress = settingsdlg.ProxyAddress; settings.ProxyUsername = settingsdlg.ProxyUsername; settings.ProxyPassword = DataProtectionHelper.Protect(settingsdlg.ProxyPassword); settings.ProxyPort = settingsdlg.ProxyPort; settings.RequestTimeout = settingsdlg.RequestTimeout; settings.CellFormatting = (int)settingsdlg.CellFormatting; settings.Save(); Analytics.Settings.Instance.AutoEscapeFilter = settingsdlg.AutoEscapeFilter; Analytics.Settings.Instance.UseProxy = settings.UseProxy; Analytics.Settings.Instance.ProxyAddress = settings.ProxyAddress; Analytics.Settings.Instance.ProxyPassword = settings.ProxyPassword; Analytics.Settings.Instance.ProxyPort = settings.ProxyPort; Analytics.Settings.Instance.ProxyUsername = settings.ProxyUsername; Analytics.Settings.Instance.RequestTimeout = settings.RequestTimeout; Analytics.Settings.Instance.MetricsXml = settings.Metrics; Analytics.Settings.Instance.DimensionsXml = settings.Dimensions; } }