Example #1
0
        private void BtnSignIn_Click(object sender, EventArgs e)
        {
            SingInForm dlg = new SingInForm();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                var user = context.Users
                           .Where(x => x.Deleted == false)
                           .SingleOrDefault(u => u.Email == dlg.Email);
                //string extension = Path.GetExtension(dlg.UserIMage);
                //string nameFile = Path.GetRandomFileName() + extension;
                //var path = Path.Combine(Directory.GetCurrentDirectory(),
                //    "user_images", nameFile);

                if (dlg.Password == ".")
                {
                    MessageBox.Show("Inccorect 2 passwords");
                }
                else if (dlg.Email == "")
                {
                    MessageBox.Show("Email is empty");
                }
                else if (user != null)
                {
                    MessageBox.Show("Email is already regestred");
                }
                else
                {
                    try
                    {
                        //try
                        //{
                        //    var bmp = ImageHelper.ComprressImage(Image.FromFile(dlg.UserIMage), 120, 80);
                        //    bmp.Save(path, ImageFormat.Jpeg);
                        //}
                        //catch (Exception ex)
                        //{
                        //    MessageBox.Show(ex.Message);
                        //}

                        ICryptoService cryptoService = new PBKDF2();

                        //New User
                        string password = dlg.Password;

                        //save this salt to the database
                        string salt = cryptoService.GenerateSalt();

                        //save this hash to the database
                        string hashedPassword = cryptoService.Compute(password);

                        DBUser dbUser = new DBUser
                        {
                            FirstName         = dlg.FirstName,
                            LastName          = dlg.LastName,
                            UserImage         = dlg.ImageToByteArray(Image.FromFile(dlg.UserIMage)),
                            MobilePhoneNumber = dlg.MobilePhoneNumber,
                            DateRegistered    = DateTime.Now,
                            LastLoginDate     = DateTime.Now,
                            Deleted           = false,
                            Email             = dlg.Email,
                            //Password = dlg.Password,
                            Password     = hashedPassword,
                            PasswordHash = salt,
                            //PasswordHash = dlg.Password.GetHashCode().ToString()
                        };

                        context.Users.Add(dbUser);
                        context.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }
Example #2
0
        private void HeaderMenu_Data_SingIn_Click(object sender, EventArgs e)
        {
            SingInForm sf = new SingInForm();

            sf.ShowDialog();
        }