Page 1 of 3

One Time Password

Posted: Wed Nov 30, 2011 9:27 am
by ebgames56
I need a script to make a one time password but with a bunch of passwords only to be able to use once to download a file.

Thanks

Re: One Time Password

Posted: Wed Nov 30, 2011 9:37 am
by Celauran
Generating random passwords should be fairly trivial. Use something like md5(microtime()) and then substr() to cut it down to the desired length.

Re: One Time Password

Posted: Wed Nov 30, 2011 9:40 am
by ebgames56
i know but. i cant get it to well see i have a database with number passwords its just not letting me login in with the numbers

Re: One Time Password

Posted: Wed Nov 30, 2011 9:42 am
by Celauran
Post the code you're using to login and we can take a look.

Re: One Time Password

Posted: Wed Nov 30, 2011 9:44 am
by ebgames56
here is the site to put in code


http://szeryk.com/Guitar%20Manifesto/download/




<?php
// Connect to your MySQL database
mysql_connect(localhost, sszeryk, ****) or die (mysql_error());

// Connect to your database
mysql_select_db(sszeryk_Purchase) or die(mysql_error());

$result = mysql_query("SELECT * FROM Codes")or die(mysql_error());

function get_rand_letters($length)
{
if($length>0)
{
$rand_id="";
for($i=1; $i<=$length; $i++)
{
mt_srand((double)microtime() * 1000000);
$num = mt_rand(1,5);
$rand_id .= assign_rand_value($num);
}
}
return $rand_id;
}



if(isset($_POST['submit'])){
$input = $_POST['password'];
$peanut = md5($input);

if($peanut == $password){
echo "<div align='center'><h2>Guitar Manifesto Download</h2>
<div style='font-size: 14px; color: green;'>You entered the correct password.</div>";
}else{
echo "<div align='center'><h2>Guitar Manifesto Download</h2>
<div style='font-size: 14px; color: red;'>Please try again.</div>
<form action='' method='post'>
<input type='password' name='password' />
<input type='submit' name='submit' value='submit' /></div>
</form>";
}
}else{
echo "<div align='center'><h2>Guitar Manifesto Download</h2>
<div style='font-size: 14px;'>Enter the password below.</div>
<form action='' method='post'>
<input type='password' name='password' />
<input type='submit' name='submit' value='submit' /></div>
</form>";
}


?>

Re: One Time Password

Posted: Wed Nov 30, 2011 9:58 am
by Celauran
Unless you have defined them as constants somewhere, you'll need quotes around your MySQL login credentials.

You have

Code: Select all

if ($peanut == $password)
but I don't see $password defined anywhere, so the comparison will always fail.

You've defined a function that never gets called. You've queried the database but aren't doing anything with the result ($result). Is this the complete code?

Re: One Time Password

Posted: Wed Nov 30, 2011 10:00 am
by ebgames56
i have the mysqlcreds and thats it.

also i want to make it so that when the password is used it gets expired like you can only use it once

Re: One Time Password

Posted: Wed Nov 30, 2011 10:16 am
by Celauran
Once per user? Once per IP? Once per email? What's to stop me from getting multiple passwords?

Re: One Time Password

Posted: Wed Nov 30, 2011 10:17 am
by ebgames56
All i want is for my music album, when someone purchase my album off my site they will recieve a code to download the album.... And you can only use that code once to download it

Re: One Time Password

Posted: Wed Nov 30, 2011 10:23 am
by Celauran
In that case, rather than having them enter a password, why not email them a link with a download token?

Code: Select all

http://yoursite.com/download.php?id=blahblahblahwhatever
Create the token when the purchase is confirmed and toggle a 'downloaded' switch once the token has been used.

Re: One Time Password

Posted: Wed Nov 30, 2011 10:25 am
by ebgames56
that costs money. i dont want to pay

Re: One Time Password

Posted: Wed Nov 30, 2011 10:25 am
by ebgames56
ohhhhhhhhhhhhhhhhhhhhhhhhh i c

Re: One Time Password

Posted: Wed Nov 30, 2011 10:26 am
by ebgames56
how would i email them a link. how would i find out there email????

Re: One Time Password

Posted: Wed Nov 30, 2011 10:27 am
by Celauran
Require it as part of the purchase form?

Re: One Time Password

Posted: Wed Nov 30, 2011 10:27 am
by ebgames56
ok but how do i make this all through paypal