开发者

Konami Code using C# and ASP.net [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 7 years ago.

开发者_运维百科 Improve this question

http://en.wikipedia.org/wiki/Konami_Code

I already done this using full javascript but how can i do this in C#/asp.net website (not winform). thanks..


So you mean the user should not find out about your ultra secret konami code when viewing the source?

It's not possible to do it entirely server-side, unless you want a postback on every keystroke, which is awkward.

You could compress and obfuscate the javascript, but I guess a user with a strong determination still can figure it out.

You could use Silverlight, but again, a user with a strong determination can unpack the XAP from the browser cache and view your DLLs in reflector.

What you could do is sending every keystroke to the server using AJAX (or maybe collect them client-side and send them in a batch), which is actually not that painfully slow. On the server you'd have to analyse the keystrokes. This code will not be visible to the user. You'd then have to simulate some push mechanism to trigger your desired reaction on the client side.


It doesn't make sense to do it in C#. Such code would have to be executed on the client side anyway, so it has to be Javascript (unless you want to send each client keystroke to the server, which would be painfully slow)

Anyway, here's a C# implementation. It's for WPF, but it wouldn't be hard to adapt it to another technology.

    private static readonly Key[] _konamiCode = new[] { Key.Up, Key.Up, Key.Down, Key.Down, Key.Left, Key.Right, Key.Left, Key.Right, Key.B, Key.A };
    int _konamiCurrentIndex = 0;

    protected override void OnPreviewKeyDown(KeyEventArgs e)
    {
        base.OnPreviewKeyDown(e);
        if (e.Key == _konamiCode[_konamiCurrentIndex])
        {
            _konamiCurrentIndex++;
            if (_konamiCurrentIndex == _konamiCode.Length)
            {
                _konamiCurrentIndex = 0;
                KonamiEasterEgg();
            }
        }
        else
        {
            _konamiCurrentIndex = 0;
        }
    }

    void KonamiEasterEgg()
    {
        // whatever you want to do when the Konami code is entered...
    }


as others already said, it doesn't make much sense to implement it fully in C#. But i could imagine some kind of combination of both JavaScript + AJAX with C#... Just some ideas :)

Possible Workflow: Scan user Input (last 10 keys) with JavaScript and push the inputs into an array (ascii code or something) and send a request via AJAX which will return the whole secret target page as a html result instead of just checking, as this would be easy to crack. Actually, this would be more like a password comparison. But you could optimize your JavaScript and clear the array on few seconds without input (idle time) like 2 seconds (so that the input must be fluent) and send the ajax request after 1 second without input so that you don't flood your own server.

JQuery will help you a lot!

Happy coding : )

  • best regards
    Thomas


See herzmeister der welten

What you could do is sending every keystroke to the server using AJAX (or maybe collect them client-side and send them in a batch), which is actually not that painfully slow. On the server you'd have to analyse the keystrokes. This code will not be visible to the user. You'd then have to simulate some push mechanism to trigger your desired reaction on the client side.

The Trigger could be the last keystroke you need as part of the combination, the user would only then be able to decipher the last keystroke, and this would offer the fewest postbacks without some client side validation.

(Would have just made a comment but lack rep)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜