Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. When the CEO becomes a developer II

When the CEO becomes a developer II

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasemysqlquestionannouncement
16 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imagiro
    wrote on last edited by
    #1

    To activate his account the user has to enter a key which is stored in the database in his account-record. How do we find this record? Well, we search the table:

    $loginname = $_POST['loginname'];
    $keyEntered = $_POST['key'];
    $query = "SELECT * FROM user";

    $result = mysql_query($query) or die(mysql_error());

    while($row = mysql_fetch_array($result)){

    if ($keyEntered == $row["activator"]){
    $sql="UPDATE user SET activator = '', status='activated' WHERE username = '$loginname'";
    mysql_query($sql);

    $time=time()+ 365\*24\*60\*60;
    setcookie("check", "1",$time);
    

    }
    }

    if ($keyEntered != $row["activator"])
    {
    $msg2="Invalid key";
    }

    So: - No escaping of the entered POST-parameters. - First query fetches ALL datasets! - WHERE-clause in second query takes the loginname given by the user, not the id of the dataset found Can this be worse?

    L P N 3 Replies Last reply
    0
    • I imagiro

      To activate his account the user has to enter a key which is stored in the database in his account-record. How do we find this record? Well, we search the table:

      $loginname = $_POST['loginname'];
      $keyEntered = $_POST['key'];
      $query = "SELECT * FROM user";

      $result = mysql_query($query) or die(mysql_error());

      while($row = mysql_fetch_array($result)){

      if ($keyEntered == $row["activator"]){
      $sql="UPDATE user SET activator = '', status='activated' WHERE username = '$loginname'";
      mysql_query($sql);

      $time=time()+ 365\*24\*60\*60;
      setcookie("check", "1",$time);
      

      }
      }

      if ($keyEntered != $row["activator"])
      {
      $msg2="Invalid key";
      }

      So: - No escaping of the entered POST-parameters. - First query fetches ALL datasets! - WHERE-clause in second query takes the loginname given by the user, not the id of the dataset found Can this be worse?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes, it can. Garnish the whole thing with some empty catch blocks. Obfuscate these horrors with a generous helping of spaghetti (code). Use only obscure abreviations as names for variables. Avoid comments at all cost. Throw in some lengthy and totally needless string manipulation to avoid having to use any other data type. Let those string manipulations fail (sometimes) because the string was null to begin with, which omits about 10000 code lines by going directly to the empty catch block. Or how about this: Send some query to get a filled dataset with several tables and many rows. Then clear out all the rows (but prevent them from being deleted in the database). This way you conveniently get a dataset to fill with your own new rows. No hassle with setting up the dataset first. And I have this and many more great ideas in one big ball of rubbish. And the spaghetti parts are so good that any attempt to replace the most horrible parts one by one is doomed to fail.

      A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

      G I 2 Replies Last reply
      0
      • L Lost User

        Yes, it can. Garnish the whole thing with some empty catch blocks. Obfuscate these horrors with a generous helping of spaghetti (code). Use only obscure abreviations as names for variables. Avoid comments at all cost. Throw in some lengthy and totally needless string manipulation to avoid having to use any other data type. Let those string manipulations fail (sometimes) because the string was null to begin with, which omits about 10000 code lines by going directly to the empty catch block. Or how about this: Send some query to get a filled dataset with several tables and many rows. Then clear out all the rows (but prevent them from being deleted in the database). This way you conveniently get a dataset to fill with your own new rows. No hassle with setting up the dataset first. And I have this and many more great ideas in one big ball of rubbish. And the spaghetti parts are so good that any attempt to replace the most horrible parts one by one is doomed to fail.

        A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

        G Offline
        G Offline
        GibbleCH
        wrote on last edited by
        #3

        If your code is clean, short, concise and has excellent method/function/variable/class names, then you can "Avoid comments at all cost."

        1 Reply Last reply
        0
        • L Lost User

          Yes, it can. Garnish the whole thing with some empty catch blocks. Obfuscate these horrors with a generous helping of spaghetti (code). Use only obscure abreviations as names for variables. Avoid comments at all cost. Throw in some lengthy and totally needless string manipulation to avoid having to use any other data type. Let those string manipulations fail (sometimes) because the string was null to begin with, which omits about 10000 code lines by going directly to the empty catch block. Or how about this: Send some query to get a filled dataset with several tables and many rows. Then clear out all the rows (but prevent them from being deleted in the database). This way you conveniently get a dataset to fill with your own new rows. No hassle with setting up the dataset first. And I have this and many more great ideas in one big ball of rubbish. And the spaghetti parts are so good that any attempt to replace the most horrible parts one by one is doomed to fail.

          A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.

          I Offline
          I Offline
          imagiro
          wrote on last edited by
          #4

          Ha! You made some good suggestions! Unfortunately the genius about who I'm talking already managed most of your ideas. I will bring more examples, you will see! :)

          1 Reply Last reply
          0
          • I imagiro

            To activate his account the user has to enter a key which is stored in the database in his account-record. How do we find this record? Well, we search the table:

            $loginname = $_POST['loginname'];
            $keyEntered = $_POST['key'];
            $query = "SELECT * FROM user";

            $result = mysql_query($query) or die(mysql_error());

            while($row = mysql_fetch_array($result)){

            if ($keyEntered == $row["activator"]){
            $sql="UPDATE user SET activator = '', status='activated' WHERE username = '$loginname'";
            mysql_query($sql);

            $time=time()+ 365\*24\*60\*60;
            setcookie("check", "1",$time);
            

            }
            }

            if ($keyEntered != $row["activator"])
            {
            $msg2="Invalid key";
            }

            So: - No escaping of the entered POST-parameters. - First query fetches ALL datasets! - WHERE-clause in second query takes the loginname given by the user, not the id of the dataset found Can this be worse?

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Clippy: I see that you entered the wrong password. The correct password is "apple"; shall I enter it for you?

            1 Reply Last reply
            0
            • I imagiro

              To activate his account the user has to enter a key which is stored in the database in his account-record. How do we find this record? Well, we search the table:

              $loginname = $_POST['loginname'];
              $keyEntered = $_POST['key'];
              $query = "SELECT * FROM user";

              $result = mysql_query($query) or die(mysql_error());

              while($row = mysql_fetch_array($result)){

              if ($keyEntered == $row["activator"]){
              $sql="UPDATE user SET activator = '', status='activated' WHERE username = '$loginname'";
              mysql_query($sql);

              $time=time()+ 365\*24\*60\*60;
              setcookie("check", "1",$time);
              

              }
              }

              if ($keyEntered != $row["activator"])
              {
              $msg2="Invalid key";
              }

              So: - No escaping of the entered POST-parameters. - First query fetches ALL datasets! - WHERE-clause in second query takes the loginname given by the user, not the id of the dataset found Can this be worse?

              N Offline
              N Offline
              Nagy Vilmos
              wrote on last edited by
              #6

              imagiro wrote:

              $time=time()+ 365*24*60*60;

              Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]


              Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

              P C A 3 Replies Last reply
              0
              • N Nagy Vilmos

                imagiro wrote:

                $time=time()+ 365*24*60*60;

                Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]


                Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

                P Offline
                P Offline
                Peter_in_2780
                wrote on last edited by
                #7

                Distant memories of childhood wonderment: Eight six four two zero(es). And yes, it has been useful these last 60-odd years. Cheers, Peter ps No idea why you got downvoted. Have my 5 in at least partial compensation.

                Software rusts. Simon Stephenson, ca 1994.

                1 Reply Last reply
                0
                • N Nagy Vilmos

                  imagiro wrote:

                  $time=time()+ 365*24*60*60;

                  Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]


                  Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

                  C Offline
                  C Offline
                  Charvak Karpe
                  wrote on last edited by
                  #8

                  Nagy Vilmos wrote:

                  Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]

                  Just last week I wrote a formula that included "numdays * 86400" and then I replaced it with "numdays * 24 * 60 * 60" because that adds clarity for the people who don't know how many seconds are in a day. If other people are going to read your code, it's easier to do 24*60*60 than to add a comment explaining why you're multiplying by 86400.

                  D D 2 Replies Last reply
                  0
                  • C Charvak Karpe

                    Nagy Vilmos wrote:

                    Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]

                    Just last week I wrote a formula that included "numdays * 86400" and then I replaced it with "numdays * 24 * 60 * 60" because that adds clarity for the people who don't know how many seconds are in a day. If other people are going to read your code, it's easier to do 24*60*60 than to add a comment explaining why you're multiplying by 86400.

                    D Offline
                    D Offline
                    djdanlib 0
                    wrote on last edited by
                    #9

                    Indeed. Your compiler should do that multiplication as part of the optimization stage anyway, so feel free to leave arithmetic on constants like that in your code as long as it improves the situation. Even if it didn't optimize that out, if you're waiting on the SQL server to retrieve your results like that, the last thing you'll notice is 2 extra integer multiplication operations.

                    1 Reply Last reply
                    0
                    • N Nagy Vilmos

                      imagiro wrote:

                      $time=time()+ 365*24*60*60;

                      Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]


                      Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

                      A Offline
                      A Offline
                      AspDotNetDev
                      wrote on last edited by
                      #10

                      I didn't, but for some reason I know there are 525,600 minutes in a year. :rolleyes:

                      [Forum Guidelines]

                      P 1 Reply Last reply
                      0
                      • A AspDotNetDev

                        I didn't, but for some reason I know there are 525,600 minutes in a year. :rolleyes:

                        [Forum Guidelines]

                        P Offline
                        P Offline
                        Peter_in_2780
                        wrote on last edited by
                        #11

                        A workable "slide rule" approximation: 1 year = 10^7.5 seconds. [A leap year is even closer! ;P ]

                        Software rusts. Simon Stephenson, ca 1994.

                        A 1 Reply Last reply
                        0
                        • P Peter_in_2780

                          A workable "slide rule" approximation: 1 year = 10^7.5 seconds. [A leap year is even closer! ;P ]

                          Software rusts. Simon Stephenson, ca 1994.

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #12

                          I guess now we know how you measure a year. :)

                          [Forum Guidelines]

                          P 1 Reply Last reply
                          0
                          • A AspDotNetDev

                            I guess now we know how you measure a year. :)

                            [Forum Guidelines]

                            P Offline
                            P Offline
                            Peter_in_2780
                            wrote on last edited by
                            #13

                            All is revealed! From the "Eight Days a Week" school of mathematical chronology. :laugh: :laugh:

                            Software rusts. Simon Stephenson, ca 1994.

                            1 Reply Last reply
                            0
                            • C Charvak Karpe

                              Nagy Vilmos wrote:

                              Does nobody know that there are 86,400 seconds ina day? [I can't prove this but I have thios ingrained in my long-term memory.]

                              Just last week I wrote a formula that included "numdays * 86400" and then I replaced it with "numdays * 24 * 60 * 60" because that adds clarity for the people who don't know how many seconds are in a day. If other people are going to read your code, it's easier to do 24*60*60 than to add a comment explaining why you're multiplying by 86400.

                              D Offline
                              D Offline
                              Dave Kreskowiak
                              wrote on last edited by
                              #14

                              Wow. So you replaced a "magic number" with a set of "magic numbers" for clarity? Replace the thing with a constant and you'd be doing far, far better.

                              A guide to posting questions on CodeProject[^]
                              Dave Kreskowiak

                              C 1 Reply Last reply
                              0
                              • D Dave Kreskowiak

                                Wow. So you replaced a "magic number" with a set of "magic numbers" for clarity? Replace the thing with a constant and you'd be doing far, far better.

                                A guide to posting questions on CodeProject[^]
                                Dave Kreskowiak

                                C Offline
                                C Offline
                                Charvak Karpe
                                wrote on last edited by
                                #15

                                #define SECONDS_IN_A_DAY 86400 is clearer and slightly educational to the reader, so definitely a better solution You trivialize my approach as using "magic numbers", but in the real world probably 90% of the population can tell what you're doing if you do 24 * 60 * 60 whilst maybe 15% of people know what 86400 is. So, I'd still say 24 * 60 * 60 is clearer than 86400 despite it being 3 "magic numbers" instead of 1. Astonishingly, if you add a fourth magic number, nearly every literate human on the Western calendar understands it with no explanation: "365 * 24 * 60 * 60".

                                D 1 Reply Last reply
                                0
                                • C Charvak Karpe

                                  #define SECONDS_IN_A_DAY 86400 is clearer and slightly educational to the reader, so definitely a better solution You trivialize my approach as using "magic numbers", but in the real world probably 90% of the population can tell what you're doing if you do 24 * 60 * 60 whilst maybe 15% of people know what 86400 is. So, I'd still say 24 * 60 * 60 is clearer than 86400 despite it being 3 "magic numbers" instead of 1. Astonishingly, if you add a fourth magic number, nearly every literate human on the Western calendar understands it with no explanation: "365 * 24 * 60 * 60".

                                  D Offline
                                  D Offline
                                  Dave Kreskowiak
                                  wrote on last edited by
                                  #16

                                  Charvak Karpe wrote:

                                  but in the real world probably 90% of the population can tell what you're doing if you do 24 * 60 * 60

                                  You haven't worked with some of the developers I work with now. No, they couldn't tell you what that code was doing... seriously.

                                  A guide to posting questions on CodeProject[^]
                                  Dave Kreskowiak

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups