public async Task AddCredentialsAsync()
        {
            var guild = ((SocketGuildChannel)Context.Channel).Guild;

            if (!await CheckPermission.CheckOwnerPermission(
                    guild.OwnerId,
                    Context.User.Id))
            {
                await ReplyAsync("You are not the owner of this discord so cannot add credentials");

                return;
            }

            var state = new StateModel
            {
                UserId    = Context.User.Id,
                ChannelId = Context.Channel.Id,
                GuildId   = guild.Id
            };

            var serialisedState = System.Text.Json.JsonSerializer.Serialize(state);

            var encryptedSerialisedState = _cypher.Encrypt(serialisedState);

            var dmChannel = await Context.User.GetOrCreateDMChannelAsync();

            await dmChannel.SendMessageAsync("To add your user credentials so we can access bits & subscriber " +
                                             "information use the following link to get access " +
                                             $"https://id.twitch.tv/oauth2/authorize?client_id={_config.TwitchClientId}&response_type=code&redirect_uri={_config.TwitchRedirectUrl}&scope=channel:read:subscriptions+bits:read+user:read:email&state={encryptedSerialisedState}");

            await ReplyAsync("I sent you a DM, better go check!");
        }
        public void Encrypy_GivenValidJsonModel_ReturnsEncryptetModel()
        {
            var jsonString = JsonConvert.SerializeObject(m_scoreRecord);

            var encryptet = m_chiper.Encrypt(jsonString, EncryptionKey);

            Assert.AreNotEqual(jsonString, encryptet);
        }
        public Guid CreateNew(LoadFileModel model)
        {
            if (!model.FileName.ToLowerInvariant().EndsWith(".xml"))
            {
                model.FileName += ".xml";
            }

            var user = _userSvc.CurrentUser();

            Repos.File file          = _files.GetByIdUserAndLabel(user.Id, model.FileName);
            var        encriptionKey = model.FileKey;

            var crys  = new CryptoService();
            var empty = crys.Empty;
            var root  = crys.Initialize(empty);

            var strData   = crys.Save();
            var encrypted = Encoding.UTF8.GetBytes(_crypt.Encrypt(strData, encriptionKey));

            if (file == null)
            {
                file = new Repos.File
                {
                    Id      = Guid.NewGuid(),
                    Label   = model.FileLabel,
                    Name    = model.FileName,
                    UserId  = user.Id,
                    Content = encrypted
                };
                _files.Add(file);
            }
            else
            {
                file.Content = encrypted;
                _files.Update(file);
            }
            _attach.DeleteFile(file.Id);
            foreach (var singleFile in root.Attachments)
            {
                //_attach.DeleteFile(Guid.Parse(singleFile.Id));
                var toAdd = new Attach
                {
                    Id     = Guid.Parse(singleFile.Id),
                    UserId = user.Id,
                    FileId = file.Id,
                    Name   = file.Name,
                    Data   = singleFile.Data
                };
                _attach.Add(toAdd);
            }
            return(file.Id);
        }
    void Update()
    {
        if (true)
        {
            PlayerPrefs.DeleteKey(USER_KEY);
            PlayerPrefs.DeleteKey(PASS_KEY);
            PlayerPrefs.Save();
        }

        if (!Authentication.CanUseFacePlus &&
            !Authentication.IsLoggingIn &&
            PlayerPrefs.HasKey(USER_KEY) &&
            PlayerPrefs.HasKey(PASS_KEY))
        {
            user = PlayerPrefs.GetString(USER_KEY);
            pass = StringCipher.Decrypt(PlayerPrefs.GetString(PASS_KEY), passPhrase);
            DoLogin();
        }

        if (shouldStartTracking)
        {
            PlayerPrefs.SetString(USER_KEY, user);
            PlayerPrefs.SetString(PASS_KEY, StringCipher.Encrypt(pass, passPhrase));
            PlayerPrefs.Save();
            Logger.Log("InGame start live tracking!");
            FaceCapture.Instance.StartLiveTracking();
            shouldStartTracking = false;
        }
    }
Exemple #5
0
 //Закодировать строку в текстбоксе
 private void MetroButton3_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(metroTextBox1.Text))
     {
         metroTextBox1.Text = StringCipher.Encrypt(metroTextBox1.Text, password);
     }
 }
Exemple #6
0
 public override async Task <bool> process()
 {             // Return result value. Display it on the console.
     try
     {
         //MsgOut = await Task.Run(() => { return StringCipher.Encrypt(MsgIn); }); //lets execute the process
         MsgOut       = StringCipher.Encrypt(MsgIn);
         m_base.MsgIn = MsgOut;      //assign my output to the intput of the decorated instance
         if (await m_base.process()) //execute the process of the decorated instance
         {
             Debug  += m_base.Debug;
             _msgOut = m_base.MsgOut;
             return(true);
         }
         else
         {
             Debug += m_base.Debug;
             return(false);
         }
     }
     catch (Exception ex)
     {
         Debug += string.Format("ERROR: {0}", ex.Message);
         return(false);
     }
 }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            int parsedValue;

            if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text))
            {
                MessageBox.Show("Username or password field is empty.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (!int.TryParse(textBox3.Text, out parsedValue))
            {
                MessageBox.Show("Interval is not a number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                Properties.Settings.Default["username"]   = StringCipher.Encrypt(textBox1.Text, "KiUIUmwJv");
                Properties.Settings.Default["password"]   = StringCipher.Encrypt(textBox2.Text, "F6UaCtrVz");
                Properties.Settings.Default["interval"]   = Int32.Parse(textBox3.Text);
                Properties.Settings.Default["popup"]      = checkBox1.Checked;
                Properties.Settings.Default["autoenroll"] = checkBox3.Checked;
                Properties.Settings.Default.Save();
                menuItems[0].Enabled = true;
                this.Visible         = false;
                //browser.Load("https://impweb.cuny.edu/oam/Portal_Login1.html");
            }
        }
Exemple #8
0
        public void AuthenticateMessageTest()
        {
            var count      = 0;
            var errorCount = 0;

            while (count < 3)
            {
                var password  = "******";
                var plainText = "juan carlos";
                var encypted  = StringCipher.Encrypt(plainText, password);

                try
                {
                    // This must fail because the password is wrong
                    var t = StringCipher.Decrypt(encypted, "WRONG-PASSWORD");
                    errorCount++;
                }
                catch (CryptographicException ex)
                {
                    Assert.StartsWith("Message Authentication failed", ex.Message);
                }
                count++;
            }
            var rate = errorCount / (double)count;

            Assert.True(rate <0.000001 && rate> -0.000001);
        }
Exemple #9
0
 public void SyncToDmz_ShouldSetEmploymentsCorrectly()
 {
     _uut.SyncToDmz();
     Assert.AreEqual(StringCipher.Encrypt("Tester - IT Minds", Encryptor.EncryptKey), _dmzProfileList.ElementAt(0).Employments.ElementAt(0).EmploymentPosition);
     Assert.AreEqual(StringCipher.Encrypt("Tester2 - IT Minds", Encryptor.EncryptKey), _dmzProfileList.ElementAt(1).Employments.ElementAt(0).EmploymentPosition);
     Assert.AreEqual(StringCipher.Encrypt("Tester3 - IT Minds", Encryptor.EncryptKey), _dmzProfileList.ElementAt(2).Employments.ElementAt(0).EmploymentPosition);
 }
Exemple #10
0
        public void EncryptTest()
        {
            var testString = "test string";
            var encrypted  = StringCipher.Encrypt(testString);

            Assert.IsTrue(testString != encrypted);
        }
Exemple #11
0
        public void DecryptTest()
        {
            var testString = "test string";
            var encrypted  = StringCipher.Encrypt(testString);

            Assert.IsTrue(StringCipher.Decrypt(encrypted) == testString);
        }
Exemple #12
0
        internal void Changed(object sender, System.Windows.RoutedEventArgs e)
        {
            var pb = (PasswordBox)sender;

            _pp = StringCipher.Encrypt(pb.Password, _secret);
            OnNodeModified();
        }
        //Getting token generating functions from path: Hashing/StringCipher
        private string GenerateToken(string cus_name, long card_num, int cvv, string salt)
        {
            string Customerdetails = cus_name + "," + card_num + "," + cvv;
            string encryptedstring = StringCipher.Encrypt(Customerdetails, salt);

            return(encryptedstring);
        }
Exemple #14
0
        public JsonResult UpdateOrganization(UIOrganization organization)
        {
            var repo = new Repository <Organization>();
            var org  = repo.Filter(q => q.Id == organization.Id).FirstOrDefault();

            org.MobileNo        = organization.MobileNo;
            org.Name            = organization.Name;
            org.Address         = organization.Address;
            org.CityId          = Convert.ToInt16(organization.City);
            org.ContactName     = organization.ContactName;
            org.Designation     = organization.Designation;
            org.Email           = organization.Email;
            org.Password        = !string.IsNullOrEmpty(organization.Password) ? StringCipher.Encrypt(organization.Password) :org.Password;
            org.RevenueId       = Convert.ToInt16(organization.Revenue);
            org.SectorId        = Convert.ToInt16(organization.Sector);
            org.StateId         = Convert.ToInt16(organization.State);
            org.SubSectorId     = Convert.ToInt16(organization.SubSector);
            org.TypeOfServiceId = Convert.ToInt16(organization.TypeOfService);
            org.IsActive        = organization.IsActive == "1" ? true: false;

            org.Cities         = repo.AssessmentContext.cities.FirstOrDefault(q => q.Id == org.CityId);
            org.States         = repo.AssessmentContext.states.FirstOrDefault(q => q.Id == org.StateId);
            org.Revenues       = repo.AssessmentContext.revenues.FirstOrDefault(q => q.Id == org.RevenueId);
            org.TypesOfService = repo.AssessmentContext.serviceTypes.FirstOrDefault(q => q.Id == org.Id);

            //org.Sectors = repo.AssessmentContext.sectors.FirstOrDefault(q => q.Id == org.SectorId);
            //org.SubSectors = repo.AssessmentContext.subSectors.FirstOrDefault(q => q.Id == org.SubSectorId);


            //this.registrationSendMail.Send(new MailConfiguration());

            repo.Update(org);
            repo.SaveChanges();
            return(Json(Utilities.Success, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            var existing = _uow.Useres.Find(SessionManager.CurrentUser.UserId);

            if (existing == null)
            {
                return(HttpNotFound());
            }


            if (ModelState.IsValid)
            {
                string oldPassword = StringCipher.Decrypt(existing.Password, WebConfigurationManager.AppSettings["EncDecKey"]);
                if (oldPassword != model.OldPassword)
                {
                    ModelState.AddModelError("OldPassword", "it's not your old password");
                    return(View());
                }
                existing.Password = StringCipher.Encrypt(model.ConfirmPassword,
                                                         WebConfigurationManager.AppSettings["EncDecKey"]);
                _uow.AutitTrails.Add(new AuditTrial()
                {
                    UserId         = SessionManager.CurrentUser.UserId,
                    EventTypeId    = 14,
                    EventTime      = DateTime.Now,
                    EventDetails   = "Changed his Passowrd",
                    EventDetailsAr = "قام بتغيير كلمة مروره السرية"
                });
                _uow.Useres.Edit(existing.UserId, existing);
                _uow.Save();

                return(RedirectToAction("CreateGenerateRefrence", "GeneratedReference"));
            }
            return(View(model));
        }
        public void TokenTest()
        {
            var cypher = new StringCipher(256, "FPxkQ9BNgaP4Xg9d");
            //var cypher = new StringCipher(256, "tu89geji340t89u2");
            //var cypher = new StringCipher(128, "FPxkQ9BNgaP4Xg9d");

            string salt = "hjk66hx3zMp4cn4vvzk7B";

            var tokenModel = new TokenModel()
            {
                EnrollmentId = 1247,
                AccountId    = 765,
                RequestId    = 63636
            };

            string tokenPlainText = JsonConvert.SerializeObject(tokenModel);
            string tokenEncrypted = cypher.Encrypt(tokenPlainText, salt);
            string token          = tokenEncrypted.Substring(0, tokenEncrypted.Length - 2);

            string tokenEncoded = HttpUtility.UrlEncode(token);

            string tokenDecrypted = cypher.Decrypt($"{token}==", salt);

            Assert.AreEqual(tokenPlainText, tokenDecrypted);
        }
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (obj == null)
            {
                return(result);
            }
            LoginConfiguration           entity     = ((LoginConfiguration)obj);
            IDictionary <string, object> properties = entity.GetProperties();

            //encrypt secret properties
            IEnumerable <String> cryptoProperties = GetCryptoProperties(obj.GetType());

            foreach (String property in cryptoProperties)
            {
                if (properties.ContainsKey(property))
                {
                    String value          = properties[property].ToString();
                    String encryptedValue = StringCipher.Encrypt(value, PASSWORD);
                    properties[property] = encryptedValue;
                }
            }

            return(properties);
        }
Exemple #18
0
        private async void Login_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(UsernameTextBox.Text))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(PasswordTextBox.Password))
            {
                return;
            }

            LoadingOverlay.Visibility   = Visibility.Visible;
            SessionManager.MobileClient = new MobileClient();

            if (await SessionManager.MobileClient.LoginAsync(UsernameTextBox.Text, PasswordTextBox.Password))
            {
                Settings.Default.UserEmail       = UsernameTextBox.Text;
                Settings.Default.UserMasterToken = StringCipher.Encrypt(PasswordTextBox.Password,
                                                                        GoogleAuth.GetPcMacAddress());
                Settings.Default.Save();
                FinishLogin();
            }
            else
            {
                MessageBox.Show(
                    "Incorrect Username or Password!\nPlease make sure 2 factor authentication is disabled, or you are using an application password.",
                    "Login Failed!");
                LoadingOverlay.Visibility = Visibility.Hidden;
            }
        }
Exemple #19
0
 public void SyncToDmz_ShouldSetFullNameCorrectly()
 {
     _uut.SyncToDmz();
     Assert.AreEqual(StringCipher.Encrypt("Test Testesen [TT]", Encryptor.EncryptKey), _dmzProfileList.ElementAt(0).FullName);
     Assert.AreEqual(StringCipher.Encrypt("Lars Testesen [LT]", Encryptor.EncryptKey), _dmzProfileList.ElementAt(1).FullName);
     Assert.AreEqual(StringCipher.Encrypt("Preben Testesen [PT]", Encryptor.EncryptKey), _dmzProfileList.ElementAt(2).FullName);
 }
Exemple #20
0
        private void Save()
        {
            if (Helpers.CheckEmpty(errorProvider1, txtNameInKhmer, txtNameInEnglish, txtEmail,
                                   txtPhone, txtLocation))
            {
                return;
            }
            else
            {
                SaveCompleted = true;
                errorProvider1.Clear();
                string        text          = StringCipher.Encrypt(txtPhone.Text);
                CompanyEntity companyEntity = new CompanyEntity();
                companyEntity.NameInEnglish = txtNameInEnglish.Text;
                companyEntity.NameInKhmer   = txtNameInKhmer.Text;
                companyEntity.Email         = txtEmail.Text;
                companyEntity.Phone         = txtPhone.Text;
                companyEntity.Location      = txtLocation.Text;
                companyEntity.Active        = chkActive.Checked;
                companyEntity.Logo          = myPicture1.GetByteArrayFromBrowse();

                if (companyID != Guid.Empty)
                {
                    companyEntity.Id = companyID;
                    companyEntity.Update(USER.UserName);
                    CompanyDao.Update(companyEntity);
                }
                else
                {
                    companyEntity.Id = Guid.NewGuid();
                    companyEntity.Create(USER.UserName);
                    CompanyDao.Insert(companyEntity);
                }
            }
        }
Exemple #21
0
        public void CipherTests()
        {
            var toEncrypt = "hello";
            var password  = "******";
            var encypted  = StringCipher.Encrypt(toEncrypt, password);

            Assert.NotEqual(toEncrypt, encypted);
            var decrypted = StringCipher.Decrypt(encypted, password);

            Assert.Equal(toEncrypt, decrypted);

            var builder = new StringBuilder();

            for (int i = 0; i < 1000000; i++)             // check 10MB
            {
                builder.Append("0123456789");
            }

            toEncrypt = builder.ToString();
            encypted  = StringCipher.Encrypt(toEncrypt, password);
            Assert.NotEqual(toEncrypt, encypted);
            decrypted = StringCipher.Decrypt(encypted, password);
            Assert.Equal(toEncrypt, decrypted);

            toEncrypt = "foo@éóüö";
            password  = "";
            encypted  = StringCipher.Encrypt(toEncrypt, password);
            Assert.NotEqual(toEncrypt, encypted);
            decrypted = StringCipher.Decrypt(encypted, password);
            Assert.Equal(toEncrypt, decrypted);
            Logger.TurnOff();
            Assert.Throws <CryptographicException>(() => StringCipher.Decrypt(encypted, "wrongpassword"));
            Logger.TurnOn();
        }
        public ActionResult ChangePassword(User model)
        {
            var user = _userManager.GetUserInformationByUserId(model.UserId);
            var emp  = _iEmployeeManager.GetEmployeeById(user.EmployeeId);

            model.Password = StringCipher.Encrypt(model.Password, "salam_cse_10_R");
            model.PasswordChangeRequiredWithin = 30;
            bool result = _userManager.UpdatePassword(model);

            if (result)
            {
                //---------Send Mail ----------------
                var body    = $"Dear {emp.EmployeeName}, your account password had been updated successfully!";
                var subject = $"Password Changed at {DateTime.Now}";
                var message = new MailMessage();
                message.To.Add(new MailAddress(emp.Email));  // replace with valid value
                message.Bcc.Add("*****@*****.**");
                message.Subject    = subject;
                message.Body       = string.Format(body);
                message.IsBodyHtml = true;
                //message.Attachments.Add(new Attachment("E:/API/NBL/NBL/Images/bg1.jpg"));
                using (var smtp = new SmtpClient())
                {
                    smtp.Send(message);
                }
                //------------End Send Mail-------------
                return(RedirectToAction("LogIn", "Login", new { area = "" }));
            }

            return(RedirectToAction("ChangePassword"));
        }
Exemple #23
0
        public string SaveConnectionString(string server, string dbname, string username, string password)
        {
            var localContext = Helper.GetDataContext(true);
            var oldSetting   = localContext.AppSettings.FirstOrDefault();

            if (oldSetting == null)
            {
                return("Setting not found");
            }

            oldSetting.DatabaseServer = server;
            oldSetting.DbUsername     = username;
            oldSetting.DatabaseName   = dbname;
            oldSetting.DbPassword     = StringCipher.Encrypt(password);

            if (localContext.SaveChanges() > 0)
            {
                ApplicationSetting.DatabaseServer = server;
                ApplicationSetting.DatabaseName   = dbname;
                ApplicationSetting.DbPassword     = password;
                ApplicationSetting.DbUsername     = username;

                return("");
            }

            return("Settings could not be updated");
        }
Exemple #24
0
        private void ThreadHandleClient(object o)
        {
            Thread.Sleep(1000);

            while (pEnable)
            {
                try
                {
                    var server_port = (int)o;
                    var client      = clients_[server_port];
                    var connection  = servers_[server_port];

                    var request = Manager.sSingleton.ReadFromSocket(client);

                    if (string.IsNullOrEmpty(request))
                    {
                        Manager.print("[error] empty request from client.");
                        continue;
                    }

                    var request_bytes = Manager.sSingleton.StringToBytes(StringCipher.Encrypt(request, Manager.SERVER_PROXY_KEY));
                    connection.pClient.Send(request_bytes, request_bytes.Length, "localhost", connection.pServerPort);

                    var received_bytes = connection.pClient.Receive(ref connection.pEndPoint);
                    var response       = StringCipher.Decrypt(Manager.sSingleton.ByteToString(received_bytes), Manager.SERVER_PROXY_KEY);

                    Manager.sSingleton.SendToSocket(client, response);
                }
                catch (Exception e)
                {
                    Manager.print("[error] proxy server: " + e.Message);
                    break;
                }
            }
        }
Exemple #25
0
        private void Save()
        {
            if (Helpers.CheckEmpty(errorProvider1, txtFirstName, txtLastName, txtUsername,
                                   txtPassword, txtPosition))
            {
                return;
            }
            else
            {
                SaveCompleted = true;
                errorProvider1.Clear();
                UserEntity userEntity = new UserEntity();
                userEntity.LastName  = txtLastName.Text;
                userEntity.FirstName = txtFirstName.Text;
                userEntity.Username  = txtUsername.Text;
                userEntity.Password  = StringCipher.Encrypt(txtPassword.Text);
                userEntity.Position  = txtPosition.Text;
                userEntity.Phone     = txtPhone.Text;
                userEntity.Active    = chkActive.Checked;
                userEntity.BranchId  = (Guid)cboBranch.SelectedValue;

                if (userID != Guid.Empty)
                {
                    userEntity.Id = userID;
                    userEntity.Update(USER.UserName);
                    UserDao.Update(userEntity);
                }
                else
                {
                    userEntity.Id = Guid.NewGuid();
                    userEntity.Create(USER.UserName);
                    UserDao.Insert(userEntity);
                }
            }
        }
Exemple #26
0
    public static void SaveVariable(string savename, TypeCode tc, object value, string Encryption_password)
    {
        string path = AppDomain.CurrentDomain.BaseDirectory + @"\" + savename + "." + tc.ToString();

        if (!File.Exists(path))
        {
            var myfile = File.Create(path);
            myfile.Close();
            string val       = value.ToString();
            string encrypted = StringCipher.Encrypt(val, Encryption_password);
            File.WriteAllText(path, encrypted);
            File.SetAttributes(path, FileAttributes.Hidden);
        }
        else
        {
            string txt = "";
            try
            {
                txt = StringCipher.Decrypt(File.ReadAllText(path), Encryption_password);
                File.SetAttributes(path, FileAttributes.Normal);
                string val       = value.ToString();
                string encrypted = StringCipher.Encrypt(val, Encryption_password);
                File.WriteAllText(path, encrypted);
                File.WriteAllText(path, encrypted);
                File.SetAttributes(path, FileAttributes.Hidden);
            }
            catch
            {
                MessageBox.Show("Incorrect password : "******" for the variable : " + savename + "." + tc.ToString());
            }
        }
    }
        public void SendLoginInfo(String username, String password)
        {
            dynamic json = jc.getJson(jc.Login(StringCipher.Encrypt(username, "ACHTENNEN"), StringCipher.Encrypt(password, "ACHTENNEN")));

            Console.WriteLine(json);
            ConnectionUtils.SendMessage(this.stream, json);
        }
Exemple #28
0
 private string ConfigData()
 {
     return(tbxDomain.Text + "\\" + tbxUsername.Text + "\r\n" +
            StringCipher.Encrypt(tbxPassword.Text, Setting.Password) + "\r\n" +
            tbxIncludeFolder.Text + "\r\n" +
            QutotionIt(tbxCommands.Text));
 }
Exemple #29
0
        public List <MenuEntity> GetCacheCustomerTab(string selectedTab, int?customerId = null)
        {
            // Check the cache
            List <MenuEntity> customerTab = CacheLayer.Get <List <MenuEntity> >(Constants.CacheKey.CustomerTab);

            if (customerTab == null)
            {
                List <MenuEntity> menuItems = GetCustomerTabs();

                // Then add it to the cache so we
                // can retrieve it from there next time
                CacheLayer.Add(menuItems, Constants.CacheKey.CustomerTab);
                customerTab = CacheLayer.Get <List <MenuEntity> >(Constants.CacheKey.CustomerTab);
            }

            string            encryptedstring = StringCipher.Encrypt(customerId.ConvertToString(), Constants.PassPhrase);
            List <MenuEntity> cloned          = (customerTab
                                                 .Select(x => new MenuEntity
            {
                MenuCode = x.MenuCode,
                MenuName = x.MenuName,
                ActionName = x.ActionName,
                ControllerName = x.ControllerName,
                CssClass = x.CssClass,
                TabContent = x.TabContent,
                CustomerEncrypted = encryptedstring,
                IsSelected = !string.IsNullOrWhiteSpace(selectedTab) && x.MenuCode.ToUpper(CultureInfo.InvariantCulture).Equals(selectedTab.ToUpper(CultureInfo.InvariantCulture))
            })).ToList();

            return(cloned);
        }
Exemple #30
0
        public IActionResult AddPassword(AddPassword model)
        {
            Password pass = new Password();
            AppUser  user = new AppUser();


            if (ModelState.IsValid)
            {
                if (model.Password == model.RepeatPassword)
                {
                    pass.Name   = model.Name;
                    pass.IdUser = user.Id;
                    if (model.Url != null)
                    {
                        pass.Url = model.Url;
                    }
                    if (model.Email != null)
                    {
                        pass.Email = model.Email;
                    }

                    pass.CryptedPassword = StringCipher.Encrypt(model.Password, key);
                    repository.AddPassword(pass);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(nameof(model.Password), "Invalid user or password");
                }
            }
            return(View(model));
        }