5/5/11

How to Write a Simple Security Script

Computer and network security is a big deal. Skilled programmers are expected to make secure programs and websites. However, computer and network security is a complex topic. New exploits are found in systems every day by both white hat (the term for a hacker who does legitimate security research in accordance with the law) and black hat (the term for a hacker who looks to compromise security systems illegally) hackers. New programmers can't hope to be able to fully secure their code until they have more experience. However, as a learning project along the way you can deploy a simple security script that checks a username and password.
    • 1

      Pick a username and password. For this simple security project, you will be "hard coding" the username and password into the script. Create two variables to store the chosen username and password, then set their values to the username and password you chose.

    • 2

      Write a prompt for a username and password. If you are using the PHP programming language, this will be a separate web page with a form for the two values, with a "login" button. The button will act as a link to the page you are actually securing and it holds your security script, sending along the username and password the user entered as variables. If you are using a terminal-based language, make a line of text above the input prompt for the username and password.

    • 3

      Set two variables to the values that the user is prompted to enter, if you are using a terminal-based script.

    • 4

      Evaluate, with an "if" statement, whether the username and password the user entered matches the username and password you hard coded into your script. Create two "if" statements for this purpose: one to evaluate the username and another to evaluate the password. If you are using PHP, this code will be on the page you are trying to secure. In this case, set the data that was sent from the previous page's form to two variables on the new page for this comparison.

    • 5

      Display the page if the username and password both evaluate correctly. You could do this by having a boolean value -- a variable that holds either the value "true" or "false" -- that starts off being set to false. The value is only set to true if the username and password are correct and the content you are guarding is placed within an "if" statement that requires the boolean value to equal true. You can customize what you want the script to display if the username and password do not match.

  • No comments: