Passwortabfrage

Hier ein Beispielcode für eine einfache Passwortabfrage. Entweder als Popup oder in eine Sektion integriert.

@title Passwort Popup

[[Auswahl]]:


Entweder als [[Popup]] oder in die Seite [[integriert]].

[[Popup]]:

    window.passwort = function () {
    
    let content = '<input type="text" id="passwort" name="name" required size="10" placeholder="Passwort?">'
    
    $.confirm({
        title: 'Bitte gib ein gültiges Passwort ein:',
        content: content,
        buttons: {
            'Flug suchen': {
                text: 'Passwort prüfen',
                btnClass: 'btn-blue',
                action: function () {
                    var passwort = this.$content.find('#passwort').val();
                    if(!passwort){
                        $.alert('Bitte gib ein Passwort ein!');
                        return false;
                    }
                    if(passwort == "123456") {
                        // do something!
                        $.alert('Richtig!');
                        window.story.go('next_section');
                    } else {
                        $.alert('Das Passwort ' + name + ' ist leider falsch!');
                    }
                }
            },
            'Abbrechen': function () {
                //close
            },
        },
        onContentReady: function () {
            // bind to events
            var jc = this;
            this.$content.find('form').on('submit', function (e) {
                e.preventDefault();

            });
        }
    });
    };


<button name="test" onClick="window.passwort();">Passwort</button>

[[next_section]]:

Das Passwort war richtig.




[[integriert]]:

    setTimeout(function() {
    window.matchPassword = function() {  
      var pw1 = $('#password').val();
      if(pw1 !== "123456")  
      {   
        $.alert("Passwort leider falsch!");  
      } else {  
        $.alert("Passwort richtig!");  
        window.story.go('next_section');
      }  
    }  
    },10);

    

<input type="password" id="password" name="pswd1"> <br><br>  

<button type = "submit" onclick="matchPassword()">Passwort prüfen</button>  

Last updated