Menu:

Sponsor

Discover Master of Alchemy, our first iPad/iPhone and iPod touch game!

Follow Me

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


User authentication - Flash & PHP

3.8 secret movie clip

The secret movieclip's timeline is made in this way:

With in the first frame the form with the user secret Question as dynamic textfield and an input text field where user must insert his secret answer in order to obtain a new password. The sumbit button has:

            
on (release) {
    errorMsg.text = "";
    if ((secretAnswer.length > 0)) {
        _root.errorMsg.text = "";
        var newP = new LoadVars();
        newP.action = "new_password";
        newP.username = userName;
        newP.email = email;
        newP.answer = secretAnswer.text;
        newP.sendAndLoad(php_file, newP, 'POST');
        registerBtn.enabled = false;
        newP.onLoad = function() {
            if (this.error != undefined) {
                _root.errorMsg.text = this.error;
                secretAnswer.text = "";
            } else {
                new_username = this.userName;
                new_pass = this.new_pass;
                gotoAndStop("ok");
            }
            registerBtn.enabled = true;
        };
    }
}

Build another loadVars object and store inside all tha variable we need to pass to PHP:
var newP = new LoadVars();
newP.action = "new_password";
newP.username = userName;
newP.email = email;
newP.answer = secretAnswer.text;
newP.sendAndLoad(php_file, newP, 'POST');

We send to PHP the variable action = "new_password", in this way PHP will read into the switch function that it must call the proper function new_password() which will check inside mysql if user has inserted his correct answer and, if correct, it generates a new password which will be returned to flash (remember that it should be better if this new password is sent via email and not directly as clear html output).
Anyway, once flash read the output, if it contains no error variable, will jump to the "ok" frame label where the user can now reads his new password and login again.

4 Files preview & download

download .zip file with files used in this tutorial