protected void btn_submit_Click(object sender, EventArgs e)
        {
            string uname = txt_emailid.Text;
            string oldpassword = CLASS.PasswordEncryption.EncryptIt(txt_oldpwd.Text);
            string newpassword = CLASS.PasswordEncryption.EncryptIt(txt_newpwd.Text);
            try
            {
                IUser checkuser = new UserItems();

                //returns a table if given email id and password are matched
                dt = checkuser.checklogin(uname, oldpassword);
                if (dt != null)
                {
                    string userid = dt.Rows[0]["Uid"].ToString();
                    bool ispwdupdated = checkuser.UpdatePassword(userid, newpassword);
                    if (ispwdupdated)
                    {
                        lbl_submit.Text = HardCodedValues.BuddaResource.PwdChangeSuccess;
                    }
                    else
                    {
                        lbl_submit.Text = HardCodedValues.BuddaResource.Error;
                    }
                }
                else
                {
                    lbl_submit.Text = HardCodedValues.BuddaResource.LoginFail;
                }
            }
            catch (Exception ex)
            {
                lbl_submit.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
        public string LoginUser(string emailid, string password)
        {
            //string flag = string.Empty;
            string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(password);
            try
            {

                IUser checkuser = new UserItems();

                //returns datatable if username and password are matched
                dt = checkuser.checklogin(emailid, encryptedpwd);
                if (dt != null)
                {
                    //flag = "Existing User";
                    this.Session["currentuser"] = dt;
                    return emailid;
                }
                else
                {
                    //flag = "Invalid User";
                    return "nouser";

                }
            }
            catch (Exception ex)
            {
                //flag = "Error: " + ex;
                return "nouser";
            }

            //return flag;
        }
        protected void btn_login_Click(object sender, EventArgs e)
        {
            string luname = txt_lusername.Text;
            string lpassword = CLASS.PasswordEncryption.EncryptIt(txt_lpassword.Text);
            try
            {
                IUser checkuser = new UserItems();

                //returns datatable if username and password are matched
                dt = checkuser.checklogin(luname, lpassword);
                if (dt != null)
                {
                    this.Session["currentuser"] = dt;
                    //lbl_login.Text = "Log In Successfull";
                    Response.Redirect("~/homepage.aspx");
                    //txt_lusername.Enabled = txt_lpassword.Enabled = false;
                }
                else
                {
                    lbl_login.Text = HardCodedValues.BuddaResource.LoginFail;
                }
            }
            catch (Exception ex)
            {
                lbl_login.Text = HardCodedValues.BuddaResource.CatchBlockError + ex.Message;
            }
        }
        public bool RegisterUser(string emailid, string password)
        {
            try
            {
                IUser checkuser = new UserItems();

                //returns the table if given emailid exists
                dt = checkuser.checkavailability(emailid);
                if (dt == null)
                {
                    string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(password);
                    BusinessEntitiesBS.UserEntities.userobj userObj = new BusinessEntitiesBS.UserEntities.userobj();

                    userObj.uname = "";
                    userObj.emailid = emailid;
                    userObj.pwd = encryptedpwd;
                    try
                    {
                        IUser userInsert = new UserItems();

                        //insert new user details in database with given values
                        userInsert.insertUser(userObj);

                        DataTable dt2 = userInsert.checklogin(emailid, encryptedpwd);

                        this.Session["currentuser"] = dt2;

                        return true;
                    }
                    catch (Exception exp)
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        protected void btn_reg_Click(object sender, EventArgs e)
        {
            if (lbl_checkemail.Text == HardCodedValues.BuddaResource.EmailIdAvailable)
            {
                //Check whether the Captcha text is correct or not
                if (this.txt_captcha.Text == this.Session["CaptchaImageText"].ToString())
                {
                    string uname = txt_username.Text;
                    string emailid = txt_emailid.Text;
                    string encryptedpwd = CLASS.PasswordEncryption.EncryptIt(txt_password.Text);

                    bool verfyDomain = verifyDomain(emailid);
                    bool chkEmail = sendEmail(emailid);

                    if (verfyDomain && chkEmail)
                    {
                        BusinessEntitiesBS.UserEntities.userobj userObj = new BusinessEntitiesBS.UserEntities.userobj();

                        userObj.uname = uname;
                        userObj.emailid = emailid;
                        userObj.pwd = encryptedpwd;
                        try
                        {
                            IUser userInsert = new UserItems();

                            //insert new user details in database with given values
                            userInsert.insertUser(userObj);

                            dt = userInsert.checklogin(emailid, encryptedpwd);
                            this.Session["currentuser"] = dt;

                            //lbl_register.Text = "Registration Successfull";
                            Response.Redirect("~/USER/ProfilePage.aspx");
                        }
                        catch (Exception exp)
                        {
                            lbl_register.Text = HardCodedValues.BuddaResource.CatchBlockError + exp.Message;
                        }
                    }
                    else
                    {
                        lbl_register.Text = "Registration Incomplete! Invalid email id or domain. Please provide valid email for regitration.";

                    }
                }
                else
                {
                    txt_captcha.Text = "";
                    lbl_captcha.Text = HardCodedValues.BuddaResource.CaptchaError;
                    // Create a random Captcha and store it in the Session object.
                    this.Session["CaptchaImageText"] = Captcha.CaptchaImage.GenerateRandomCode(7);
                    txt_captcha.Focus();
                }
            }
            else
            {
                txt_emailid.Focus();
            }
        }