One Time Password

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

One Time Password

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: One Time Password

Post 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.
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: One Time Password

Post by Celauran »

Post the code you're using to login and we can take a look.
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post 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>";
}


?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: One Time Password

Post 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?
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: One Time Password

Post by Celauran »

Once per user? Once per IP? Once per email? What's to stop me from getting multiple passwords?
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: One Time Password

Post 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.
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post by ebgames56 »

that costs money. i dont want to pay
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post by ebgames56 »

ohhhhhhhhhhhhhhhhhhhhhhhhh i c
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post by ebgames56 »

how would i email them a link. how would i find out there email????
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: One Time Password

Post by Celauran »

Require it as part of the purchase form?
ebgames56
Forum Contributor
Posts: 103
Joined: Thu Oct 06, 2011 10:43 am

Re: One Time Password

Post by ebgames56 »

ok but how do i make this all through paypal
Post Reply