TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-23-2009, 09:12 PM   #1 (permalink)
The Wanderer
 
Mike's Avatar
 
Join Date: Jun 2009
Posts: 11
Thanks: 0
Mike is on a distinguished road
Default Pin System

Hi guys, i have a special problem to solve :P

this is the thing, i need a pin system, so if a user enters a pin (a 12 digits code might be) he will gain acces to certain area.

The problem is i just can't figure out a correct and secure way to generate those codes, should i have to generate them randomly, how many should i generate or anything...?

if anyone of you have info about a similar system please let me know.
Mike is offline  
Reply With Quote
Old 07-23-2009, 09:26 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Mike View Post
Hi guys, i have a special problem to solve :P

this is the thing, i need a pin system, so if a user enters a pin (a 12 digits code might be) he will gain acces to certain area.

The problem is i just can't figure out a correct and secure way to generate those codes, should i have to generate them randomly, how many should i generate or anything...?

if anyone of you have info about a similar system please let me know.
Random generation is fine, one random generation will be sufficient per pin.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-24-2009, 01:45 AM   #3 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

just make sure that the pin generated is unique. I haven't done anything like this, but I am guessing the encrypting functions (like md5, sha1, base, ...) could come in handy along with the random function.
tony is offline  
Reply With Quote
Old 07-24-2009, 03:36 AM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by tony View Post
just make sure that the pin generated is unique. I haven't done anything like this, but I am guessing the encrypting functions (like md5, sha1, base, ...) could come in handy along with the random function.
I don't see how an encryption function would be of any use, MD5 and SHA1 both turn something into a given length base-16 number (meaning numbers and a-f). This has less possibilities than all letters and numbers.

Uniqueness is only a requirement if it is the only source of verification. Not allowing keys to be duplicated lessens the possible amount combination the user could have. Although this makes no real difference in practice.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-24-2009, 03:49 AM   #5 (permalink)
The Wanderer
 
Mike's Avatar
 
Join Date: Jun 2009
Posts: 11
Thanks: 0
Mike is on a distinguished road
Default

Thanks for your help :)
well VI, i need only number codes in fact.

I was thinking of another problem :P, what if after a couple of year i've generated tons of Pins, wha should i do?? reset them all? (i don't think this is a good idea, cause people might use their old pins), maybe adding one more digit?? (adding a digit is a pain in the ass for users, but all new pins would be unique)
Mike is offline  
Reply With Quote
Old 07-24-2009, 04:01 AM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Mike View Post
Thanks for your help :)
well VI, i need only number codes in fact.

I was thinking of another problem :P, what if after a couple of year i've generated tons of Pins, wha should i do?? reset them all? (i don't think this is a good idea, cause people might use their old pins), maybe adding one more digit?? (adding a digit is a pain in the ass for users, but all new pins would be unique)
Seven digits will cover 9,999,999 pins, five alpha-numeric characters will hold 36^5 or 52,521,875 different possibilities. But when you get even close to full, it becomes a security risk. Even using .1% will take 1,000 tries on average to correctly guess. I highly recommend a user name and password opposed to singularly validating by a pin.

At work, for any system of reasonable value we force at least eight characters with at least one number, upper case letter and punctuation mark. This means that each user has 8^63 possible combination, but a strong password (ten or more chars) has at least 10^63 .

If you use sha1 to hash your passwords (and make guessing the sha1 value directly available), you are limited to 28^16 since that is the number of possible combination a 28 place base-16 digit can hold. But that is why you shouldn't store the password even if hashed directly in the cookie.
__________________

Village Idiot is offline  
Reply With Quote
Old 07-24-2009, 07:49 AM   #7 (permalink)
The Acquainted
 
Hightower's Avatar
 
Join Date: May 2009
Location: Durham, UK
Posts: 134
Thanks: 9
Hightower is on a distinguished road
Default

The way I've done this in the past was:

PHP Code:
$pin md5(rand()); 
And then cut the $pin value down to the first 'x' amount of characters.
__________________
Hightower's Softpolio
Send a message via MSN to Hightower
Hightower is offline  
Reply With Quote
Old 07-24-2009, 08:30 AM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

What i would do is generate a new pin every 30 days that way you can delete the old one and it wont be so many :)
codefreek is offline  
Reply With Quote
Old 07-24-2009, 02:54 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by codefreek View Post
What i would do is generate a new pin every 30 days that way you can delete the old one and it wont be so many :)
How would that reduce the numbers? Deleting one and creating another really does nothing,
__________________

Village Idiot is offline  
Reply With Quote
Old 07-24-2009, 03:03 PM   #10 (permalink)
The Wanderer
 
Mike's Avatar
 
Join Date: Jun 2009
Posts: 11
Thanks: 0
Mike is on a distinguished road
Default

Yeah VI, a username and password is more secure, but suppose this is a paid service, you register in a website by paying online. But these pins are a tangible way to register (they will be a piece of paper wich will be bought somewhere :P), so after buying these pin you can register in the site without paying online, in other words those pins are an alternative of paying online.
Mike is offline  
Reply With Quote
Old 07-24-2009, 03:06 PM   #11 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

If it can be written down, make it alpha-numeric (non case sensitive) and rather long. 15 characters would be easily suitable.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pagelite Pagination System ioan1k Show Off 3 01-29-2013 12:40 PM
Freelance Suite: Client & Project Management Software CLCook Show Off 2 09-14-2008 10:50 AM
Plugin System freenity Advanced PHP Programming 12 04-01-2008 08:15 PM
Designing a tagging system Alan @ CIT Advanced PHP Programming 4 03-10-2008 03:25 PM
Are operating system commands system unique? Aaron Absolute Beginners 4 12-28-2007 07:19 PM


All times are GMT. The time now is 12:29 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design