Exemple #1
0
        public ActionResult forgot_password(login_model forgot_password)
        {
            if (ModelState.IsValid)
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress("*****@*****.**");
                msg.To.Add("*****@*****.**");
                msg.Subject    = "Recover your Password";
                msg.Body       = ("Your Username is:" + "rihad789" + "<br/><br/>" + "Your Password is:" + "password");
                msg.IsBodyHtml = true;

                SmtpClient smt = new SmtpClient();
                smt.Host = "smtp.gmail.com";
                NetworkCredential ntwd = new NetworkCredential();
                ntwd.UserName             = "******"; //Your Email ID
                ntwd.Password             = "******";                       // Your Password
                smt.UseDefaultCredentials = true;
                smt.Credentials           = ntwd;
                smt.Port      = 587;
                smt.EnableSsl = true;
                smt.Send(msg);
            }
            return(View());
        }
Exemple #2
0
        public ActionResult login(login_model login_model)
        {
            var key = "b14ca5898a4e4133bbce2ea2315a1916";

            string email    = login_model.email;
            string password = login_model.password;

            string connStr = ConfigurationManager.ConnectionStrings["QBDDBContex"].ConnectionString;

            SqlConnection conn = new SqlConnection(connStr);

            SqlCommand cmd  = conn.CreateCommand();
            SqlCommand cmd2 = conn.CreateCommand();
            SqlCommand cmd3 = conn.CreateCommand();

            cmd.CommandText = "SELECT Name,Email FROM users where UserID=@userID and Password=@password";
            cmd.Parameters.Add("@userID", SqlDbType.VarChar).Value   = email;
            cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = password;

            cmd2.CommandText = "SELECT COUNT(*) FROM users where UserID=@userID and Password=@password";
            cmd2.Parameters.Add("@userID", SqlDbType.VarChar).Value   = email;
            cmd2.Parameters.Add("@password", SqlDbType.VarChar).Value = password;

            cmd3.CommandText = "SELECT COUNT(*) FROM users where UserID=@userID";
            cmd3.Parameters.Add("@userID", SqlDbType.VarChar).Value   = email;
            cmd3.Parameters.Add("@password", SqlDbType.VarChar).Value = password;

            SqlDataReader myreader;

            if (ModelState.IsValid == true)
            {
                conn.Open();

                int email_count = (int)cmd3.ExecuteScalar();
                int user_count  = (int)cmd2.ExecuteScalar();
                if (email_count == 1)
                {
                    if (user_count == 1)
                    {
                        try
                        {
                            myreader = cmd.ExecuteReader();
                            while (myreader.Read())
                            {
                                string name   = myreader["Name"].ToString();
                                string userID = myreader["Email"].ToString();
                                Session["DisplayName"] = name;
                                Session["userID"]      = EncryptString(key, userID);
                            }
                            return(RedirectToAction("Index", "Home"));
                        }
                        catch (Exception)
                        {
                            ModelState.AddModelError("password", "Somethingt is wrong.Please try again");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("password", "Password don;t match");
                    }
                }
                else
                {
                    ModelState.AddModelError("Email", "Email not found.Please register");
                }
            }



            return(View());
        }