/// <summary> /// Old save function /// </summary> /// <param name="Attempts"></param> /// <returns></returns> private static async Task <bool> SaveFileAsync <T>(StorageFile file, ObservableCollection <T> DeliveredData, int Attempts = 0) where T : BaseItem { try { foreach (var item in DeliveredData.Where(x => x.Secured && !x.Encrypted)) { item.Name = Crypting.Encrypt(item.Name); item.Description = Crypting.Encrypt(item.Description); item.Encrypted = true; } XmlSerializer Serializ = new XmlSerializer(typeof(ObservableCollection <T>)); using (Stream XmlStream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(file.Name, CreationCollisionOption.ReplaceExisting)) { Serializ.Serialize(XmlStream, DeliveredData); } return(true); } // When file is unavailable catch (Exception e) when((e.Message.Contains("denied") || e.Message.Contains("is in use")) && (Attempts < 10)) { return(await SaveFileAsync(file, DeliveredData, Attempts + 1)); } catch /*(Exception e)*/ { return(false); } }
public string Login(CredentialsModel data) { //-------------- here comes username and password check and writing token to database // u tokenu moze da stoji i broj koji pokazuje na kom mestu pocinje username string password = data.password; string username = data.username; ApplicationUser user = UserManager.Find(username, password); if (user == null) { return("invalid attempt"); } //--- then token creation var userAgent = Request.Headers.GetValues("User-Agent"); //var referer = Request.Headers.GetValues("Referer"); var referer = "Referer"; string token = userAgent + "|" + "IGG" + "|" + referer + "|" + user.UserName;// + username; // here put smart combination for token string tokenEncripted = Crypting.Encrypt(token); return(tokenEncripted); }
/// <summary> /// Share item via Share menu /// </summary> /// <param name="obj">Shared item</param> public async void ShareItemAsync(T item) { DataTransferManager daTranManaItem = DataTransferManager.GetForCurrentView(); daTranManaItem.DataRequested += DaTranManaItem_DataRequested; string itemTypeName = item.GetType().Name; if (item == null) { return; } CurrentItem = item; var typeOfItemList = System.Enum.GetValues(typeof(ItemTypeEnum)).Cast <ItemTypeEnum>().ToList(); var clone = (T)item.Clone(); if (item.Secured) { clone.Name = Crypting.Encrypt(item.Name); clone.Description = Crypting.Encrypt(item.Description); } var sharedData = new ItemStorage <T> { TypeOfItem = typeOfItemList[typeOfItemList.IndexOf(typeOfItemList.FirstOrDefault(x => x.ToString() == itemTypeName))], Items = new System.Collections.ObjectModel.ObservableCollection <T>() { clone } }; try { XmlSerializer Serializ = new XmlSerializer(typeof(ItemStorage <T>)); using (Stream XmlStream = ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(ShareFileItem, CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult()) { Serializ.Serialize(XmlStream, sharedData); } } catch (Exception e) { Debug.WriteLine(e.Message); } var shareFile = await ApplicationData.Current.LocalFolder.GetFileAsync(ShareFileItem); shareFileList = new List <StorageFile> { shareFile }; DataTransferManager.ShowShareUI(); }
private void BtnCreateUser_OnClick(object sender, RoutedEventArgs e) { string connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SqlRUsers;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; SqlConnection connection = new SqlConnection(connectionString); Salting salting = new Salting(); var salt = salting.GetSalt(); Hashing hashing = new Hashing(); var hash = hashing.GetHash(salt, txtCreatePassword.Password); var encryptedConnectionString = Crypting.Encrypt(txtConnectionString.Text); try { if (connection.State == ConnectionState.Closed && txtConfirmPassword.Password.Equals(txtCreatePassword.Password)) { connection.Open(); } else { MessageBox.Show("Confirm Password does not match Password."); } String query = "INSERT into Users (UserName,ConnectionString, Password, Salt) VALUES (@Username, @ConnectionString, @Password, @Salt)"; SqlCommand sqlCmd = new SqlCommand(query, connection); sqlCmd.CommandType = CommandType.Text; sqlCmd.Parameters.AddWithValue("@Username", txtCreateUsername.Text); sqlCmd.Parameters.AddWithValue("@ConnectionString", encryptedConnectionString); sqlCmd.Parameters.AddWithValue("@Password", hash); sqlCmd.Parameters.AddWithValue("@Salt", salt); if (sqlCmd.ExecuteNonQuery() != 0) { LoginScreen login = new LoginScreen(); login.Show(); this.Close(); } else { MessageBox.Show("Failed creating new user!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } }
/// <summary> /// Save data to file /// </summary> /// <param name="Attempts">Number of attempts</param> /// <returns>True, if save was succesful</returns> protected async Task <bool> SaveDataAsync(int Attempts = 0) { try { foreach (var item in ItemsSource.Where(x => x.Secured && !x.Encrypted)) { item.Name = Crypting.Encrypt(item.Name); item.Description = Crypting.Encrypt(item.Description); item.Encrypted = true; } var typeOfItemList = System.Enum.GetValues(typeof(ItemTypeEnum)).Cast <ItemTypeEnum>().ToList(); ItemStorage <T> itemStorage = new ItemStorage <T>() { Items = GetFinalCollection(), TypeOfItem = typeOfItemList[typeOfItemList.IndexOf(typeOfItemList.FirstOrDefault(x => x.ToString() == nameof(T)))] }; XmlSerializer Serializ = new XmlSerializer(typeof(ItemStorage <T>)); using (Stream XmlStream = await ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync(FileName, CreationCollisionOption.ReplaceExisting)) { Serializ.Serialize(XmlStream, /*DeliveredData*/ itemStorage); } foreach (var item in ItemsSource.Where(x => x.Secured && x.Encrypted)) { item.Name = Crypting.Decrypt(item.Name); item.Description = Crypting.Decrypt(item.Description); item.Encrypted = false; } return(true); } // When file is unavailable catch (Exception e) when((e.Message.Contains("denied") || e.Message.Contains("is in use")) && (Attempts < 10)) { return(await SaveDataAsync(Attempts + 1)); } catch (Exception e) { Debug.WriteLine(e.Message); return(false); } }
//Insp -> vlastni typ pripony public override void Execute(object parameter) { if (parameter is ListViewBase itemList) { if (itemList.Items.Count == 0) { return; } string itemTypeName = itemList.Items[0].GetType().Name; var typeOfItemList = System.Enum.GetValues(typeof(ItemTypeEnum)).Cast <ItemTypeEnum>().ToList(); var sharedData = new ItemStorage <T> { TypeOfItem = typeOfItemList[typeOfItemList.IndexOf(typeOfItemList.FirstOrDefault(x => x.ToString() == itemTypeName))] }; foreach (var item in new ObservableCollection <T>(itemList.SelectedItems.Cast <T>().Select(x => (T)x.Clone()).ToList())) { T itemToShare = item; if (itemToShare.Secured) { itemToShare.Name = Crypting.Encrypt(itemToShare.Name); itemToShare.Description = Crypting.Encrypt(itemToShare.Description); } sharedData.Items.Add(item); } try { XmlSerializer Serializ = new XmlSerializer(typeof(ItemStorage <T>)); using (Stream XmlStream = ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync("Share.tdn", CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult()) { Serializ.Serialize(XmlStream, sharedData); } } catch (Exception e) { Debug.WriteLine(e.Message); } DataTransferManager.ShowShareUI(); } }
//Регистрация #region //Запись в реестр даты установки public static void SetDate() { try { RegistryKey dateKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\UAI", false); if (dateKey == null || dateKey.GetValue("id") == null || (string)dateKey.GetValue("id") == "") { dateKey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\UAI"); dateKey.SetValue("id", Crypting.Encrypt(DateTime.Now.ToOADate().ToString()), RegistryValueKind.String); } dateKey.Close(); } catch (Exception e1) { e1.MessageError(); } }
//Insp -> vlastni typ pripony /// <inheritdoc/> public override void Execute(object parameter) { if (parameter is ListViewBase itemList) { if (itemList.Items.Count == 0) { return; } string itemTypeName = itemList.Items[0].GetType().Name; var sharedData = new ItemStorage <T> { TypeOfItem = itemTypeName }; foreach (var item in new List <T>(itemList.SelectedItems.Cast <T>().Select(x => (T)x.Clone()).ToList())) { T itemToShare = item; if (itemToShare.Secured) { itemToShare.Name = Crypting.Encrypt(itemToShare.Name); itemToShare.Description = Crypting.Encrypt(itemToShare.Description); } sharedData.Items.Add(item); } try { XmlSerializer serializer = new XmlSerializer(typeof(ItemStorage <T>)); using Stream xmlStream = ApplicationData.Current.LocalFolder.OpenStreamForWriteAsync("Share.isuf", CreationCollisionOption.ReplaceExisting).GetAwaiter().GetResult(); serializer.Serialize(xmlStream, sharedData); } catch (Exception e) { LogService.AddLogMessage(e.Message, logLevel: Base.Enum.LogLevel.Debug); throw new Base.Exceptions.Exception("Unhandled exception", e); } DataTransferManager.ShowShareUI(); } }
public string Login(FormCollection data) { //-------------- here comes username and password check and writing token to database // u tokenu moze da stoji i broj koji pokazuje na kom mestu pocinje username string password = data["password"]; string username = data["username"]; User user = Models.User.GetByUsernameAndPassword(username, password); if (user == null) { return("invalid attempt"); } //--- then token creation var userAgent = HttpContext.Request.Headers["User-Agent"]; var referer = HttpContext.Request.Headers["Referer"]; string token = userAgent + "|" + user.userType + "|" + referer + "|" + user.username;// + username; // here put smart combination for token string tokenEncripted = Crypting.Encrypt(token); Logbook book = new Logbook(); book.action = Logbook.ACTION_LOGGED_IN; book.userID = user.ID; book.time = DateTime.Now; book.projectID = null; book.filename = null; book.textbox = null; book.Save(); return(tokenEncripted); }
private void button2_Click(object sender, EventArgs e) { textBox4.Text = Crypting.Encrypt(textBox3.Text); }
private void button11_Click(object sender, EventArgs e) { Crypted.Text = Crypting.Encrypt("true"); }