public string Login(LoginModel loginModel) { if (!this._repository.IsExistingUser(loginModel.Email)) { throw new Exception("User is not existing."); } var user = this._repository.GetUserByEmail(loginModel.Email); if (loginModel.Password != PasswordCipher.Decode(user.Password)) { throw new Exception("Incorrect password!"); } var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim("UserID", user.UserId.ToString()) }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials( new SymmetricSecurityKey( Encoding.UTF8 .GetBytes(this._appSettings.JWT_Secret)), SecurityAlgorithms.HmacSha256Signature) }; var tokenHandler = new JwtSecurityTokenHandler(); var securityToken = tokenHandler.CreateToken(tokenDescriptor); var token = tokenHandler.WriteToken(securityToken); return(token); }
//When the Submit button is clicked, this method is called. private void Submit() { // Check that all of the fields have valid input. if (!IsInputValid()) { return; } Database db = new Database(); //Check if the password has changed or not. if (!String.IsNullOrEmpty(Password) && Password.Length > 0) { SelectedService.HashedPassword = PasswordCipher.Encrypt(Password, new UserInfo().MasterPassword); } SelectedService.LastUpdated = DateTime.Now.AddHours(-1); // The time on PCs is one hour ahead for some reason. //Attempt to update the service in the database, then close the window. if (db.UpdateService(SelectedService)) { Core.PrintDebug(String.Format("Service {0} updated successfully.", SelectedService.ServiceName)); this.CloseAction(); } else { //Show the errors to the user. this.ErrorsList.Clear(); this.ErrorsList.Add("An error occured."); this.Errors = true; } }
private void Submit() { if (!IsInputValid()) { return; } Database db = new Database(); Service service = new Service(); service.ServiceName = this.ServiceName; service.UserName = this.LoginName; service.Email = this.EmailAddress; service.Website = this.Website; service.HashedPassword = PasswordCipher.Encrypt(this.Password, new UserInfo().MasterPassword); service.PasswordHash = ""; service.Description = this.Description; service.LastUpdated = DateTime.Now.AddHours(-1); // The time on PCs is one hour ahead for some reason. if (db.AddService(service)) { Core.PrintDebug(String.Format("Service {0} added successfully.", service.ServiceName)); this.CloseAction(); } else { this.ErrorsList.Clear(); this.ErrorsList.Add("An error occured."); this.Errors = true; } }
protected string Token(Usuario _usuario) { string StartToken = PasswordCipher.Encrypt(_usuario.Username); string MidToken = PasswordCipher.Encrypt(_usuario.Fullname); string EndToken = PasswordCipher.Encrypt("superUltraSecretToken"); return($"{StartToken}.{MidToken}.{EndToken}"); }
public static void Add(string login, string password, int roleId = 3) { using var db = new DbCinema(); db.Users .Value(user => user.Login, login) .Value(user => user.Password, PasswordCipher.ConvertPassword(password)) .Value(user => user.RoleId, roleId) .Insert(); }
public static bool Login(string login, string password) { using var db = new DbCinema(); string encodedPassword = PasswordCipher.ConvertPassword(password); var queryable = from user in db.Users where user.Login == login && user.Password == encodedPassword select user; return(queryable.ToList().Count > 0); }
public IEnumerable <PersonalCloudInfo> LoadCloud() { var deviceName = Globals.Database.LoadSetting(UserSettings.DeviceName) ?? Environment.MachineName; return(Globals.Database.Table <CloudModel>().Select(x => { var alibaba = Globals.Database.Table <AlibabaOSS>().Where(y => y.Cloud == x.Id).Select(y => { var config = new OssConfig { OssEndpoint = y.Endpoint, BucketName = y.Bucket, }; using var cipher = new PasswordCipher(y.Id.ToString("N", CultureInfo.InvariantCulture), x.Key); config.AccessKeyId = cipher.DecryptContinuousText(y.AccessID); config.AccessKeySecret = cipher.DecryptContinuousText(y.AccessSecret); return new StorageProviderInfo { Id = y.Id, Type = StorageProviderInstance.TypeAliYun, Name = y.Name, Visibility = (StorageProviderVisibility)y.Visibility, Settings = JsonConvert.SerializeObject(config) }; }); var azure = Globals.Database.Table <AzureBlob>().Where(y => y.Cloud == x.Id).Select(y => { var config = new AzureBlobConfig { BlobName = y.Container }; using var cipher = new PasswordCipher(y.Id.ToString("N", CultureInfo.InvariantCulture), x.Key); config.ConnectionString = cipher.DecryptTextOnce(y.Parameters); return new StorageProviderInfo { Id = y.Id, Type = StorageProviderInstance.TypeAzure, Name = y.Name, Visibility = (StorageProviderVisibility)y.Visibility, Settings = JsonConvert.SerializeObject(config) }; }); var providers = new List <StorageProviderInfo>(); providers.AddRange(alibaba); providers.AddRange(azure); return new PersonalCloudInfo(providers) { Id = x.Id.ToString("N", CultureInfo.InvariantCulture), DisplayName = x.Name, NodeDisplayName = deviceName, MasterKey = Convert.FromBase64String(x.Key), TimeStamp = x.Version, Apps = new List <AppLauncher>(), }; })); }
public async Task <User> Register(User user) { if (this._repository.IsExistingUser(user.Email) == false) { user.Password = PasswordCipher.Encode(user.Password); var registeredUser = await this._repository.Register(user); this._templateService.CreateTemplate(user.UserId); return(registeredUser); } else { throw new System.Exception("Email is already taken."); } }
public static void Update(int id, string?password = null, int?roleId = null) { using var db = new DbCinema(); var user = Get(id); if (password != null) { user.Password = PasswordCipher.ConvertPassword(password); } if (roleId != null) { user.RoleId = (int)roleId; } db.Update(user); }
public void SaveCloud(IEnumerable <PersonalCloudInfo> cloud) { Globals.Database.DeleteAll <CloudModel>(); Globals.Database.DeleteAll <AlibabaOSS>(); Globals.Database.DeleteAll <AzureBlob>(); foreach (var item in cloud) { var id = new Guid(item.Id); Globals.Database.Insert(new CloudModel { Id = id, Name = item.DisplayName, Key = Convert.ToBase64String(item.MasterKey), Version = item.TimeStamp, }); foreach (var provider in item.StorageProviders) { switch (provider.Type) { case StorageProviderInstance.TypeAliYun: { var config = JsonConvert.DeserializeObject <OssConfig>(provider.Settings); var model = new AlibabaOSS { Id = provider.Id, Cloud = id, Name = provider.Name, Visibility = (int)provider.Visibility, Endpoint = config.OssEndpoint, Bucket = config.BucketName, }; if (model.Id == Guid.Empty) { model.Id = Guid.NewGuid(); } using var cipher = new PasswordCipher(model.Id.ToString("N", CultureInfo.InvariantCulture), item.MasterKey); model.AccessID = cipher.EncryptContinuousText(config.AccessKeyId); model.AccessSecret = cipher.EncryptContinuousText(config.AccessKeySecret); Globals.Database.Insert(model); continue; } case StorageProviderInstance.TypeAzure: { var config = JsonConvert.DeserializeObject <AzureBlobConfig>(provider.Settings); var model = new AzureBlob { Id = provider.Id, Cloud = id, Name = provider.Name, Visibility = (int)provider.Visibility, Container = config.BlobName }; if (model.Id == Guid.Empty) { model.Id = Guid.NewGuid(); } using var cipher = new PasswordCipher(model.Id.ToString("N", CultureInfo.InvariantCulture), item.MasterKey); model.Parameters = cipher.EncryptTextOnce(config.ConnectionString); Globals.Database.Insert(model); continue; } } } } CloudSaved?.Invoke(this, EventArgs.Empty); }