0

Ok so I searched and could not seem to find anything that I am looking for exactly.

Background on what I am trying to accomplish: I have a website that will require no log in information as it is a confidential website and I don't want anything posted linked to any ONE account. So the way I am planning on this working is whenever someone creates a post you must fill out a form for example... Title - Information - Passphrase (simple word) - Passcode (5 digits from 10000 - 99999).

Now the reason for the possibility of accessing later is so they can edit or delete the post after the fact of creating without linking a account to identify them as stated above.

I have the simple following code to edit the code but how would I make it where say (passPhrase and passCode) have to match to pull up associated data? I will have a form before I access the edit page to type in correct info.

FORM TO REACH EDIT PAGE

<div id="form-holder">
        <form action="function/example.php" method="post"> 
            <h3>Pass ID:</h3>
            <input type="text" name="ID" id="ID">
            <h3>Passcode:<br /></h3>
            <input type="text" name="passcode" id="passcode">
            <p><input class="button" type="submit" value="Edit"></p>
        </form>
    </div>

EDIT PAGE:

<?php
$server = "*****";
$user = "*****";
$pass = "*****";
$dbname = "*****";

//Creating connection for mysqli

$conn = new mysqli($server, $user, $pass, $dbname);

//Checking connection

if($conn->connect_error){
 die("Connection failed:" . $conn->connect_error);
}

$article_id = $_GET['id'];

if( ! is_numeric($article_id) )
  die("Looks like you are lost!  <a href='#'>Back to Home</a> ");

$query = "SELECT * FROM `DBname` WHERE `ID` =$article_id LIMIT 0 , 30";

$comments = mysqli_query($conn,$query);

while($row = mysqli_fetch_array($comments, MYSQL_ASSOC))
{

    $title = $titleHere['title'];
    $info = $infoHere['info'];

    $title = htmlspecialchars($row['title'],ENT_QUOTES);
    $info = htmlspecialchars($row['info'],ENT_QUOTES);

echo "<form action='function/update-post.php?id=$article_id' method='post'>";
echo "<h3>Title:</h3>";
echo "<input type='text' name='title' id='title' value='$title'>";
echo "<h3>info:</h3>";
echo "<textarea name='info' id='info'>$info</textarea>";
echo "<p><input class='button' type='submit' value='Update'></p>";  
echo "</form>";
}
?>

I found many guides on account based solutions I guess this is what makes this request different is the fact that there are no accounts. And the user really does not have the ability of knowing the Key ID of the post.

Any help would be appreciated and hopefully others will benefit from this.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Sheldon C
  • 63
  • 9
  • Just save a [hash](https://stackoverflow.com/questions/1602776/what-is-password-hashing) of the passphrase on the row containing the post data? First check if the passphrase and/or passcode are correct before updating the table. – JiFus Mar 04 '18 at 16:23
  • Lets say your users will post articles - just an example, . create a form for the user to write the article and append auto credential generator like the user id and pass code, but you need to ask the user for the email address where you will send there access keys. to access there work, a simple link will works and restrict the page with a login form so as the owner of that work can edit it or do any thing. i think you understand. –  Mar 04 '18 at 16:29
  • That would work except for the fact that I don't want any way to link the user to the post they created. – Sheldon C Mar 04 '18 at 16:53

1 Answers1

0

you use a database for the login and store the user and password. I would go a little further and encrypt the password in the db, then at sign in time encrypt the password. then use a count statement to see if there is a row that has the hash style password with the user name. best methods to use is pdo with prepared statements, oh and turn off error reporting in php so it doesn't output in the browser, just the log file should be recording the error. for confidentiality, you just don't have that info in their table. The last task you will have to do is set up a cron job to clear the website access log. This is where IP addresses are logged.

also I would change your form to all post type so the edit process can not be booked marked and open for attack. so I would remove the id out of the url and bring it into the form like so:

   echo '<input type="hidden" name="id" value="'.$article_id.'" >';

also you should sanitize the user's post varibles in the fallowing php page like :

         $var1=htmlentities($_POST['var1'], ENT_QUOTES);
drtechno
  • 298
  • 2
  • 9
  • _encrypt the password in the db_ I hope you mean HASH and not encrypt – RiggsFolly Mar 04 '18 at 16:43
  • simple hash, not mcrypt – drtechno Mar 04 '18 at 16:50
  • 1
    Then maybe you shoudl amend your answer – RiggsFolly Mar 04 '18 at 16:51
  • The passphrase and passcode are stored on the same line as the post title and information. I just want to be able to access only if the passcode and passphrase match. – Sheldon C Mar 04 '18 at 16:55
  • yes but you still use two points, otherwise it would get confused if someone reuses the same password. otherwise you would have to do something like store the unix time (all numbers, no spaces) add it to the password, hash it then store that unix time in a seperate colum so it could be added to the posted password from the form, then hash and compare. your password or pass phrase should be unique if you are comparing just one variable for a login. – drtechno Mar 04 '18 at 17:03
  • "The passphrase and passcode are stored on the same line as the post title and information. I just want to be able to access only if the passcode and passphrase match." ok, so the posting is on the same line. That would be simple select on that table. if you using the same username and password, and the edit/delete button on the post has a login form dialog, you would bring forward the unix timestamp variable to that form in a hidden input, so the php file you post to unlock the edit knows which line you are editing – drtechno Mar 04 '18 at 17:12
  • you can go even simpler if you use the auto increment field after posting to edit then it would be user, pass, and line# instead of combining a timestamp to the password – drtechno Mar 04 '18 at 17:17