Exemple #1
0
        public bool checkEmail()
        {
            bool          status = false;
            var           CL     = new commonLogic();
            SqlConnection cnn    = CL.connect();

            try
            {
                SqlCommand command;
                string     sql;
                sql     = "SELECT * FROM users WHERE email = @email";
                command = new SqlCommand(sql, cnn);
                command.Parameters.AddWithValue("@email", Email);
                SqlDataReader dataReader = command.ExecuteReader();

                if (dataReader.HasRows)
                {
                    while (dataReader.Read())
                    {
                        var    ID                = dataReader["id"].ToString();
                        var    Email             = dataReader["email"].ToString();
                        var    FristName         = dataReader["first_name"].ToString();
                        var    LastName          = dataReader["last_name"].ToString();
                        String verification_code = CL.GetUniqueKey(49);

                        cnn.Close();
                        SqlConnection con = CL.connect();
                        try
                        {
                            SqlCommand cmd;
                            string     query = @"IF EXISTS(SELECT * FROM reset_password WHERE email = @email)
                        UPDATE reset_password 
                        SET verification_code = @verification_code
                        WHERE email = @email
                    ELSE
                        INSERT INTO reset_password(email, verification_code) VALUES(@email, @verification_code);";

                            cmd = new SqlCommand(query, con);
                            cmd.Parameters.AddWithValue("@email", Email);
                            cmd.Parameters.AddWithValue("@verification_code", verification_code);
                            cmd.CommandType = CommandType.Text;
                            cmd.ExecuteNonQuery();
                            var Body = "Hi " + FristName + ",<br/><br/>Please <a href='http://*****:*****@chd.com", Email, "CHD password reset", Body);
                        }
                        catch (Exception e)
                        {
                            CL.getLog("error while updating unique id to table" + e);
                            con.Close();
                            return(false);
                        }
                        con.Close();
                        break;
                    }
                    status = true;
                }
                else
                {
                    status = false;
                }
                return(status);
            }
            catch (Exception e)
            {
                CL.getLog("error while updating unique id to table" + e);
                cnn.Close();
                return(false);
            }
            cnn.Close();
            return(status);
        }