0

Basically, what I'd like to do is have a JavaScript function that checks whether you've entered a specific string -- but I don't want that string to be actually visible in the source code. In my mind, it would go something like this:

function checkPass(input) {
    if (encrypt(input) === 'OJqqyaQUD4APlZvAg3fvCii8Os9qBr23tlzWwjbw') {
        alert('Success');
    } else {
        alert('Fail');
    }

}

function encrypt(input) {
    //pass it through some encryption algorithm
}

How might I accomplish this –– ideally, without any external libraries?

12
  • Do you have any encryption algorithm on your mind ? Commented Feb 2, 2016 at 22:14
  • 1
    I wouldn't use clientside code for that. What are you trying to do? Commented Feb 2, 2016 at 22:14
  • What @putvande meant to say is, even if you implement an encryption algorithm it will still be visible by simply looking up the source code. So no use of encryption. Commented Feb 2, 2016 at 22:15
  • @putvande I have no choice in this case, unfortunately. But it's not protecting anything especially important; this is purely just another obstacle that people might have to get through in order to make the obfuscated code even harder to use if they steal it. Commented Feb 2, 2016 at 22:15
  • 1
    @Cliff: If one implements his own algorithm in a Javascript function it will be visible in source code. Commented Feb 2, 2016 at 22:19

1 Answer 1

2

Because the javascript can be seen in the source, there is not much you can do.

Minify - in order to make it harder to read and obfuscation

Another good thing is to use http://javascript2img.com/ to make it very hard to read.

Sign up to request clarification or add additional context in comments.

7 Comments

I guess I'd hoped javascript might have 64-bit RSA encryption built in.
Client side javascript cant be used for this kind of stuff unfortunately
The problem with all these common obfuscators is that they provide a decoding tool for their algorithm...which basically subverts the point of the obfuscation.
I've changed the link of obfuscator to the best i could found, claims the hardest to read.
Well im not saying to use instead of serves side validation, just trying to provide good answer. I think OP knows he should not use this on anything critical on his app.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.