Example #1
0
        public static int UpdatePassword(LoginUser user)
        {
            string result = "";

            // Check log in with old password
            if (HashLogin(user) == (int)SuccessEnum.Success)
            {
                result = "Pass";
            }

            //Send PasswordHash && SaltHash to DataBase for saving
            if (result == "Pass")
            {
                try
                {
                    // Get salt hash
                    user.Salt = Hasher.SetSalt();
                    // Encode password + salt
                    user.PasswordHash = Hasher.EncodeFull(user.Salt, user.NewPassword);
                    return(LoginDao.UpdatePassword(user));
                }
                catch (Exception)
                {
                    return((int)SuccessEnum.Fail);
                }
            }
            else
            {
                return((int)SuccessEnum.Fail);
            }
        }
Example #2
0
        public ActionResult Index(string name, string password)
        {
            LoginDao login_dao = new LoginDao();

            if (login_dao.Login(name, password) == 1)
            {
                EmployeeDao employee_dao = new EmployeeDao();
                UserLogin   userlogin    = new UserLogin();
                userlogin.Type            = 1;
                userlogin.ID              = employee_dao.GetIDByLogin(name);
                userlogin.Login           = name;
                userlogin.Name            = employee_dao.GetNameByID(userlogin.ID);
                userlogin.GroupEmployeeID = employee_dao.GetGroupEmployeeIDByLogin(name);
                Session["UserLogin"]      = userlogin;
                return(RedirectToAction("Blank", "Blank", new { Area = "Admin" }));
            }
            else if (login_dao.Login(name, password) == 2)
            {
                CustomerDao cus_dao   = new CustomerDao();
                UserLogin   userlogin = new UserLogin();
                userlogin.Type       = 2;
                userlogin.ID         = cus_dao.GetIDByLogin(name);
                userlogin.Login      = name;
                userlogin.Name       = cus_dao.GetNameByID(userlogin.ID);
                Session["UserLogin"] = userlogin;
                return(RedirectToAction("HomePage", "HomePage"));
            }
            else
            {
                ModelState.AddModelError("loitaikhoan", "Tài khoản hoặc mật khẩu không chính xác");
            }
            return(View("Index"));
        }
Example #3
0
        public ActionResult Cadastrar(Entidade entidade, Login login)// entidade login recebe o que o usuario digitou
        {
            EntidadeDao entidadedao = new EntidadeDao();

            entidade.Login = login;
            //Se O voluntario já existir atualiza os Dados
            if (entidade.id > 0)
            {
                LoginDao logindao = new LoginDao();
                logindao.Atualizar(login);

                entidade.Loginid = login.id;
                entidadedao.Atualizar(entidade);

                //Atualiza a sessao e redireciona para o menu principal
                entidade.Login      = logindao.BuscarPorId(entidade.Loginid);
                Session["Entidade"] = entidade;
                return(RedirectToAction("Index", "VinculoAfinidade"));
            }

            //Caso contrario cria novo registro
            else
            {
                entidadedao.Adicionar(entidade);
            }

            return(RedirectToAction("Index", "Login"));

            //Adiciona ou atuliza o Objeto na sessão
        }
Example #4
0
        public JsonResult RegistrarUsuario(string user, string pass, int typeuser, int typeadmin)
        {
            LoginBean logBean = new LoginBean();
            LoginDao  logDao  = new LoginDao();
            string    result  = "";

            logBean = logDao.sp_ValidaUsuario(user);
            if (logBean.sMensaje == "notexists")
            {
                logBean = logDao.sp_RegistroUsuario(user, pass, typeuser, typeadmin);
                if (logBean.sMensaje == "success")
                {
                    result = "goodinsert";
                }
                else
                {
                    result = "errorinsert";
                }
            }
            else
            {
                result = "existsuser";
            }
            var data = new { resp = result };

            return(Json(data));
        }
Example #5
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            using (TranMng TM = new TranMng())
            {
                LoginDao LD = new LoginDao();
                string   id = TextBox1.Text;

                DUser duser = LD.Login(id);

                if (duser != null)
                {
                    if (duser.Password == TextBox2.Text)
                    {
                        Session["id"] = duser.UserId;
                        Server.Transfer("Menu.aspx");
                    }
                    else
                    {
                        Server.Transfer("LoginError.html");
                    }
                }
                else
                {
                    Server.Transfer("LoginError.html");
                }
            }
        }
Example #6
0
        public static int NewLogin(LoginUser user)
        {
            try
            {
                // Get salt
                user.Salt = Hasher.SetSalt();
                // Encode
                user.PasswordHash = Hasher.EncodeFull(user.Salt, user.Password);

                // Check that there is no duplicate username in the DB
                if (LoginDao.SearchUserName(user.UserName) == (int)SuccessEnum.Success)
                {
                    // Add new Login to the DB
                    return(LoginDao.NewLogin(user));
                }
                else
                {
                    // Return Search fail message
                    return(LoginDao.SearchUserName(user.UserName));
                }
            }
            catch (Exception)
            {
                return((int)SuccessEnum.Fail);
            }
        }
        private void CheckLogin()
        {
            try
            {
                LoaderControl loader = new LoaderControl();
                loader.Show();
                loader.Activate();
                User objUser = new LoginDao().Login(UserName.Text, Password.Password);

                if (objUser != null)
                {
                    SessionManager.UserId    = objUser.UserId;
                    SessionManager.FirstName = objUser.FirstName;
                    SessionManager.LastName  = objUser.LastName;
                    SessionManager.UserRole  = objUser.RoleName;

                    loader.Close();
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    this.Close();
                    mainWindow.Activate();
                }
                else
                {
                    message.Text = "Invalid Username/Password.";
                    loader.Show();
                    loader.Close();
                }
            }
            catch (Exception)
            {
            }
        }
Example #8
0
        private static string GetSalt(string userName)
        {
            // Retrieve salt hash from database
            string salt = LoginDao.GetSalt(userName);

            return(salt);
        }
        public ActionResult Index(loginModel loginModel)
        {
            var log = LoginDao.ClientLogin(loginModel.userName, loginModel.password).ToList();

            if (ModelState.IsValid)
            {
                if (log[0].email != null)
                {
                    ViewData["datalogin"] = log;
                    //add session
                    Session["tenKH"]    = log[0].tenKH;
                    Session["email"]    = log[0].email;
                    Session["idUser"]   = log[0].idUser;
                    Session["idKH"]     = log[0].idKH;
                    Session["thongbao"] = "ok";
                    return(RedirectToAction("Check"));
                }
                else
                {
                    Session["thongbao"] = "fail";
                    ViewBag.error       = "Login failed";
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Example #10
0
        public static bool Acessar(Login log)
        {
            LoginDao dao = new LoginDao();

            log.validacao = dao.Teste(log);
            return(log.validacao);
        }
Example #11
0
        public JsonResult DesbloquearUsuario(int keyuser, int status, string passactive)
        {
            int       user    = Convert.ToInt32(Session["keyUser"]);
            LoginBean logBean = new LoginBean();
            LoginDao  logDao  = new LoginDao();
            string    result  = "";

            logBean = logDao.sp_ValidaUsuario_EnSesion(passactive, user);
            if (logBean.sMensaje == "success")
            {
                logBean = logDao.sp_BloquearActivar_Usuarios(keyuser, status);
                if (logBean.sMensaje == "success")
                {
                    result = "correct";
                }
                else
                {
                    result = "incorrect";
                }
            }
            else
            {
                result = "errorpass";
            }
            var resp = new { resp = result };

            return(Json(resp));
        }
Example #12
0
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            LoginDao loginDao = new LoginDao();
            bool     c        = loginDao.check(txtTenDN.Text, txtMatKhau.Text);

            if (c == true)
            {
                FormMain f = new FormMain();

                this.Hide();
                tenDN   = txtTenDN.Text;
                matKhau = txtMatKhau.Text;
                DataTable dt = loginDao.quyen(tenDN);
                DataRow   dr = dt.Rows[0];
                int       d  = Int32.Parse(dr["idChucVu"].ToString());
                if (d == 1)
                {
                    quyen = "admin";
                }
                else
                {
                    quyen = "nhanvien";
                }
                this.Hide();
                f.ShowDialog();
                this.Show();
            }
            else
            {
                MessageBox.Show("Tài khoản hoặc mật khẩu không chính xác !", "Thong bao");
            }
        }
Example #13
0
        public int CheckExistDataHaveIPAdd(IDto loginDto, out int iResult, out string message)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            return(loginDao.CheckExistDataHaveIPAdd(dto, out iResult, out message));
        }
Example #14
0
        public static int HashLogin(LoginUser user)
        {
            try
            {
                // Get salt
                user.Salt = GetSalt(user.UserName);

                // Hash
                user.PasswordHash = Hasher.EncodeFull(user.Salt, user.Password);

                // Log in
                if (LoginDao.Login(user) == (int)SuccessEnum.Success)
                {
                    return((int)SuccessEnum.Success);
                }
                else
                {
                    return((int)SuccessEnum.Fail);
                }
            }
            catch (Exception)
            {
                return((int)SuccessEnum.Fail);
            }
        }
Example #15
0
        public ActionResult Cadastrar(Voluntario voluntario, Login login)
        {
            VoluntarioDao voluntariodao = new VoluntarioDao();

            voluntario.Login = login;
            //Se O voluntario já existir atualiza os Dados
            if (voluntario.id > 0)
            {
                LoginDao logindao = new LoginDao();
                logindao.Atualizar(login);

                voluntario.Loginid = login.id;
                voluntariodao.Atualizar(voluntario);

                //Atualiza a sessao e redireciona para o menu principal
                voluntario.Login      = logindao.BuscarPorId(voluntario.Loginid);
                Session["Voluntario"] = voluntario;
                return(RedirectToAction("Index", "VinculoAfinidade"));
            }

            //Caso contrario cria novo registro
            else
            {
                voluntariodao.Adicionar(voluntario);
            }

            return(RedirectToAction("Index", "MenuPrincipal"));
        }
Example #16
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new LoginDao();
                var result = dao.Login(model.UserName, Encryptor.MD5Hash(model.PassWord));
                if (result == "Success")
                {
                    var user        = dao.GetUserByID(model.UserName);
                    var userSession = new UserLoginSession();

                    userSession.UserName = user.Name_User;
                    userSession.UserID   = user.Id_User;
                    Session.Add(Constant.USER_SESSION, userSession);

                    return(RedirectToAction("Index", "Home"));
                }
                else if (result == "InCorrect")
                {
                    ModelState.AddModelError("", "Tài Khoản hoặc mật khẩu không chính xác");
                }
                else if (result == "Locked")
                {
                    ModelState.AddModelError("", "Tài Khoản đã bị khóa");
                }
            }

            return(View("Index"));
        }
Example #17
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var dao    = new LoginDao();
                var result = dao.Login(model.adminName, Encrypt.MD5Hash(model.password));
                if (result == 1)
                {
                    var admin        = dao.GetByName(model.adminName);
                    var adminSession = new AdminLogin();
                    adminSession.adminID   = admin.adminId;
                    adminSession.adminName = admin.adminName;

                    Session.Add(CommonConstant.ADMIN_SESSION, adminSession);
                    return(RedirectToAction("Index", "Home"));
                }
                else if (result == 0)
                {
                    ModelState.AddModelError("", "Mat khau khong dung");
                }
                else if (result == -1)
                {
                    ModelState.AddModelError("", "Tai khoan khong ton tai");
                }
            }
            return(View("Login"));
        }
Example #18
0
        public int CheckLogin(IDto loginDto, out int iResult, out string employeeCode, out string displayName, out string skin)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            dto.Password = UserSession.Md5(dto.Password);
            return(loginDao.CheckExistData(dto, out iResult, out employeeCode, out displayName, out skin));
        }
Example #19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         LoginDao loginDao = new LoginDao();
         loginDao.sendPassword(email.Text);
     }
 }
Example #20
0
        public JsonResult UsuariosRestantes()
        {
            List <LoginBean> logBean = new List <LoginBean>();
            LoginDao         logDao  = new LoginDao();

            logBean = logDao.sp_UsersSinEmpresa();
            return(Json(logBean));
        }
Example #21
0
        //public int CheckLogin(IDto loginDto, out int iResult, out string employeeCode, out string displayName)
        //{
        //    LoginDao loginDao = new LoginDao();
        //    LoginDto dto = (LoginDto)loginDto;
        //    dto.Password = UserSession.Md5(dto.Password);
        //    return loginDao.CheckExistData(dto, out iResult, out employeeCode, out displayName);
        //}
        public int CheckExistDataHaveIPAdd(IDto loginDto, out int iResult, out string employeeCode, out string displayName, out string ipAddress, out string computerName)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            dto.Password = UserSession.Md5(dto.Password);
            return(loginDao.CheckExistDataHaveIPAdd(dto, out iResult, out employeeCode, out displayName, out ipAddress, out computerName));
        }
Example #22
0
        /// <summary>
        /// Constructor of the presenter
        /// </summary>
        /// <param name="loginView">View of the presenter</param>
        /// <param name="loginDao">Data Access Object of the presenter</param>
        public LoginPresenter(LoginView loginView, LoginDao loginDao)
        {
            Logger.debug("Initializing Login Presenter", origin: "ChatMail.LoginPresenter");
            m_loginView = loginView;
            m_loginDao  = loginDao;

            Login();
        }
Example #23
0
        public int CheckMessage(LoginDto loginDto, out string message)
        {
            LoginDao loginDao = new LoginDao();
            LoginDto dto      = (LoginDto)loginDto;

            //dto.Password = UserSession.Md5(dto.Password);
            return(loginDao.CheckMessage(dto, out message));
        }
Example #24
0
        public JsonResult ListadoUsuarios(int tipo, int user)
        {
            List <LoginBean> logBean = new List <LoginBean>();
            LoginDao         logDao  = new LoginDao();

            logBean = logDao.sp_Datos_Usuarios(tipo, user);
            return(Json(logBean));
        }
Example #25
0
        // 登録内容を抜き出すための処理を記述
        public DataTable Select(LoginEntity loginEntity)
        {
            // ログインビジネスロジック用のDao(DataAccessObject)のインスタンス LoginDao を生成
            LoginDao LoginDao = new LoginDao();

            // LoginDao のログイン内容をデータベースに登録する処理 LoginInsertExecute へ loginEntity を渡し実行
            return(LoginDao.GetUserTable(loginEntity));
        }
Example #26
0
        // ログイン内容を登録するための処理を記述
        public void LoginRegistration(LoginEntity loginEntity)
        {
            // ログインビジネスロジック用のDao(DataAccessObject)のインスタンス LoginDao を生成
            LoginDao LoginDao = new LoginDao();

            // LoginDao のログイン内容をデータベースに登録する処理 LoginInsertExecute へ loginEntity を渡し実行
            LoginDao.LoginInsertExecute(loginEntity);
        }
Example #27
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            LoginDao  loginDao  = new LoginDao();
            LoginView loginView = new LoginView(loginDao);

            Application.Run(loginView);
        }
Example #28
0
        public ActionResult LogOn(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                var result = LoginDao.CheckUser_1(model.UserName, model.Password);

                if (result == -3)
                {
                    ViewBag.Message = "Đã có lỗi xảy ra! Không thể đăng nhập. Hãy thử lại sau";
                    return(View("LogOn", model));
                }
                else if (result == -2)
                {
                    ViewBag.Message = "Sai tên tài khoản.";
                    return(View("LogOn", model));
                }
                else if (result == -1)
                {
                    ViewBag.Message = "Tài khoản đã bị khóa. Vui lòng lên hệ với quản trị viên";
                    return(View("LogOn", model));
                }
                else if (result == 0)
                {
                    ViewBag.Message = "Sai mật khẩu. Hãy kiểm tra lại mật khẩu";
                    return(View("LogOn", model));
                }
                else
                {
                    //Đăng nhập thành công, phân quyền người dùng truy cập
                    var userLogon = LoginDao.CheckUser(model.UserName, model.Password);

                    if (userLogon != null)
                    {
                        if (userLogon.RoleID.Value == 1)
                        {
                            Session[CommonContanst.USER_SESSION] = new UserLogin()
                            {
                                UserID = userLogon.UserID, UserName = userLogon.UserName
                            };
                            FormsAuthentication.SetAuthCookie(userLogon.UserName, true);

                            return(RedirectToAction("Index", "InOut"));
                        }
                        else
                        {
                            FormsAuthentication.SetAuthCookie(userLogon.UserName, true);
                            return(RedirectToAction("Index", "Home", new { area = "" }));
                        }
                    }
                }
                ViewBag.Message = "Vui lòng kiểm tra lại tên đăng nhập và mật khẩu";
                return(View("LogOn", model));
            }
            return(View("LogOn", model));
        }
Example #29
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new UserDao().GetByUsername(model.UserName);
                if (user.ConfirmStatus == true)
                {
                    var Result = new LoginDao().Login(model.UserName, Encryptor.MD5Hash(model.PassWord));
                    if (Result == 1)
                    {
                        var User = new UserDao().GetByUsername(model.UserName);
                        Session[Constants.USER_INFO]     = User;
                        Session[Constants.WEBSITE_COLOR] = User.ColorWebsite;
                        var userSession = new UserLogin();
                        userSession.UserName = User.UserName;
                        userSession.UserID   = User.ID;

                        Session[Constants.USER_SESSION] = userSession;
                        new LogDao().SetLog("Login", null, ((User)Session[Constants.USER_INFO]).ID);
                        //Session.Add(Constants.USER_SESSION, userSession);
                        if (Session[Constants.CURRENT_URL] != null)
                        {
                            return(Redirect((string)Session[Constants.CURRENT_URL]));
                        }
                        return(RedirectToAction("Index", "Home"));
                    }
                    else if (Result == 0)
                    {
                        ModelState.AddModelError("", "Không tồn tại tài khoản");
                    }
                    else if (Result == -1)
                    {
                        ModelState.AddModelError("", "Tài khoản đang bị khoá");
                    }
                    else if (Result == -2)
                    {
                        ModelState.AddModelError("", "Mật khẩu không đúng");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Đăng nhập không hợp lệ");
                    }
                }
                else
                {
                    new LogDao().SetLog("Login", "Đến xác nhận mã", ((User)Session[Constants.USER_INFO]).ID);
                    return(RedirectToAction("ConfirmCode", user));
                }
            }
            else
            {
                TempData["ValidationSumary"] = "Lỗi";
            }
            return(View("Index"));
        }
Example #30
0
        public String cadastrar(String email, String senha, String ConfSenha)
        {
            LoginDao Dao = new LoginDao();

            this.mensagem = Dao.cadastrar(email, senha, ConfSenha);
            if (Dao.tem)
            {
                this.tem = true;
            }
            return(mensagem);
        }