Exemple #1
0
        public ActionResult Login(Users user)
        {
            using (Entities db = new Entities())
            {
                //user.password = HashPassword.hash(user.password);
                foreach (Users u in db.Users.ToArray())
                {
                    if (u.login == user.login && HashPassword.hash(user.password, u.salt) == u.password)
                    {
                        Session["UserID"] = u.Id;

                        Session["UserLogin"] = u.login;
                        return(Redirect("~/Wallet/Index"));
                    }
                }
            }


            ModelState.AddModelError("LoginError", "Login or Password is wrong.");
            return(View());
        }
Exemple #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string UserName = inputUsername.Text;
            string Password = inputPassword.Password.ToString();

            Password = HashPassword.hash(Password);
            //bool check = NguoiDungDAO.CheckTaiKhoan(UserName, Password);
            string GetPassword = NguoiDungDAO.GetMatKhauByUser(UserName);

            if (!Password.Equals(GetPassword))
            {
                MessageBox.Show("Sai tài khoản hoặc mật khẩu!\nVui lòng nhập lại...");
            }
            else
            //MessageBox.Show("Đăng nhập thành công!");
            {
                //string HoTen = NguoiDungDAO.GetHoTenByUser(UserName);

                Trangchu tc = new Trangchu(UserName);
                //Trangchu tc = new Trangchu();
                tc.Show();
                this.Close();
            }
        }
Exemple #3
0
        public async Task <ActionResult> Register(Users user)
        {
            if (ModelState.IsValid)
            {
                using (Entities db = new Entities())
                {
                    bool isEmail = IsEmailExist(user.email);
                    bool isLogin = IsLoginExist(user.login);

                    if (isLogin)
                    {
                        ModelState.AddModelError("LoginExist", "Login already exist.");
                        return(View(user));
                    }
                    if (isEmail)
                    {
                        ModelState.AddModelError("EmailExist", "Email already exist.");
                        return(View(user));
                    }
                    if (!isLogin && !isEmail)
                    {
                        user.salt = HashPassword.createSalt();

                        user.password        = HashPassword.hash(user.password, user.salt);
                        user.confirmPassword = HashPassword.hash(user.confirmPassword, user.salt);
                        db.Users.Add(user);
                        // db.SaveChanges();
                        ViewBag.Message = "success";

                        List <string> addressInfo = await GenerateAddress();

                        PublicKey publicKey = new PublicKey();
                        publicKey.HashCode = addressInfo[1];
                        db.PublicKey.Add(publicKey);

                        Signature signature = new Signature();
                        signature.HashCode = addressInfo[2];
                        db.Signature.Add(signature);
                        db.SaveChanges();

                        int lastUsersId = 0;
                        foreach (Users u in db.Users.ToArray())
                        {
                            lastUsersId += 1;
                        }

                        Address address = new Address();
                        address.UserId      = lastUsersId;
                        address.AddressHash = addressInfo[0];
                        address.CurrencyId  = 1;
                        address.PublicKeyId = lastUsersId;
                        address.SignatureId = lastUsersId;

                        db.Address.Add(address);
                        db.SaveChanges();
                    }
                }
                ModelState.Clear();
            }
            return(View());
        }