0

I am a beer distributor and I need site visitors to enter their license # on certain pages but there is no way for me to know all of the licenses in the state. I am currently using the default wordpress password protect page feature in the "Publish" section.

Is there a php file that I can change where instead of having the password be a specific number I can tell it to allow any random number?

And what code would I need? I do not know much php.

Or maybe there is a plugin that will do this but I could not find any after searching quite a bit.

Thank you very much for your help.

1
  • 1
    Password protection that accepts any random number isn't much password protection. There is no database you can access to validate the license number? Are you using the built in post password system or something you've built yourself?
    – s_ha_dum
    Commented Jul 3, 2013 at 14:18

2 Answers 2

0

i agree with s_ha_dum, this is not exactly very protective... but what you could do is build a validation form with jquery and if it passes then convert into the actual password.

example:

real password you created: 0123456789

user enters any ten digits: 6537268574

with jquery you can store the value entered somewhere (if you will need it further on) and then change that password field to '0123456789'

two caveats: as mentioned before, really not much protection at all... and also, this would mean that everyone is logging into the same user, which could present some problems down the road.

4
  • and naturally... if they enter something that is not ten digits, or whatever format you choose, the jquery validation catches it and calls it invalid... Commented Jul 3, 2013 at 14:53
  • It is not to log into the page. My client just wants to scare regular consumers away from the page because certain pages have prices. I do not really need it to be protective. New liquor stores open every day. I don't think there is a database of licenses to grab from. Basically it is not the end of the world if someone enters the page.
    – Thomas
    Commented Jul 3, 2013 at 18:03
  • well, then the answer above will work. Commented Jul 3, 2013 at 18:05
  • Would you be able to help me with the code. I do not know php or jquery very much to write my own code like that. Would there be an easier way where I can just change the php file somehow?
    – Thomas
    Commented Jul 3, 2013 at 18:48
0

okay, first you want to limit the length of the input to the desired number of digits:

<input type="text" name="license" maxlength="10">

  • set maxlength to the number you need.

http://www.w3schools.com/tags/att_input_maxlength.asp

with this code (jquery - put it in your themes/theme_folder/js/functions.js - and make sure you are calling the jquery files and this js file in the front end) you can limit the input to only numerals, backspace, and delete:

$(document).ready(function() {
$("#txtboxToFilter").keydown(function(event) {
    // Allow only backspace and delete
    if ( event.keyCode == 46 || event.keyCode == 8 ) {
        // let it happen, don't do anything
    }
    else {
        // Ensure that it is a number and stop the keypress
        if (event.keyCode < 48 || event.keyCode > 57 ) {
            event.preventDefault(); 
        }   
    }
});
});

since this is technically not password protecting you could leave it at this, and just make this a required field to proceed to the next page.

although if you do have an actual password you can just use jquery .text(); to change it to that password when you click on submit:

$('#submit').click(function(){
    $("#txtboxToFilter").text("0123456789");
});

http://api.jquery.com/text/

if this solves your problem or if it helped you please mark it as an answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.