Ankündigung

Einklappen
Keine Ankündigung bisher.

Username und Password Check

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Username und Password Check

    Hallo Leute.

    Ich bin noch ein ziemlicher Anfänger wenn es um php geht.
    ich habe ein Problem.
    Ich möchte in einen signup Script ein Username check machen wenn z.B. ein username schon vorhanden ist das man ein andern eingeben muss.
    und beim passwort nur das beide gleich sein müssen.

    Das ist mein code.
    PHP-Code:
     <?php
    //signup.php
    include 'header.php';

    include_once 
    'inc/php/config.php';
    include_once 
    'inc/php/functions.php';

    //setup some variables/arrays
    $action = array();
    $action['result'] = null;

    $text = array();

    //check if the form has been submitted
    if(isset($_POST['signup'])){

        
    //cleanup the variables
        //prevent mysql injection
        
    $username mysql_real_escape_string($_POST['username']);
        
    $password mysql_real_escape_string($_POST['password']);
        
    $email mysql_real_escape_string($_POST['email']);
        
        
    //quick/simple validation
        
    if(empty($username)){ $action['result'] = 'error'array_push($text,'You forgot your username'); }
        if(empty(
    $password)){ $action['result'] = 'error'array_push($text,'You forgot your password'); }
        if(empty(
    $email)){ $action['result'] = 'error'array_push($text,'You forgot your email'); }
        
        if(
    $action['result'] != 'error'){
                    
            
    $password md5($password);    
                
            
    //add to the database
            
    $add mysql_query("INSERT INTO `users` VALUES(NULL,'$username','$password','$email',0,'','')");
            
            if(
    $add){
                
                
    //get the new user id
                
    $userid mysql_insert_id();
                
                
    //create a random key
                
    $key $username $email date('mY');
                
    $key md5($key);
                
                
    //add confirm row
                
    $confirm mysql_query("INSERT INTO `confirm` VALUES(NULL,'$userid','$key','$email')");    
                
                if(
    $confirm){
                
                    
    //include the swift class
                    
    include_once 'inc/php/swift/swift_required.php';
                
                    
    //put info into an array to send to the function
                    
    $info = array(
                        
    'username' => $username,
                        
    'email' => $email,
                        
    'key' => $key);
                
                    
    //send the email
                    
    if(send_email($info)){
                                    
                        
    //email sent
                        
    $action['result'] = 'success';
                        
    array_push($text,'Thanks for signing up. Please check your email for confirmation!');
                    
                    }else{
                        
                        
    $action['result'] = 'error';
                        
    array_push($text,'Could not send confirm email');
                    
                    }
                
                }else{
                    
                    
    $action['result'] = 'error';
                    
    array_push($text,'Confirm row was not added to the database. Reason: ' mysql_error());
                    
                }
                
            }else{
            
                
    $action['result'] = 'error';
                
    array_push($text,'User could not be added to the database. Reason: ' mysql_error());
            
            }
        
        }
        
        
    $action['text'] = $text;

    }

    ?>

    <?= show_errors($action); ?>

    <form method="post" action="">

        <fieldset>
        
            <ul>
                <li>
                    <label for="username">Username:</label>
                    <input type="text" name="username" />
                </li>
                <li>
                    <label for="password">Password:</label>
                    <input type="password" name="password" />
                </li>
                <li>
                    <label for="email">Email:</label>
                    <input type="text" name="email" />    
                </li>
                <li>
                    <input type="submit" value="Signup Now" class="large blue button" name="signup" />            
                </li>
            </ul>
            
        </fieldset>
        
    </form>

  • #2
    Na dann schau in die DB ob der User schon vorhanden ist und die Passwörter musst du dann schon vergleichen.
    openSuSE - linux for open minds

    Kommentar


    • #3
      Wohl nicht verstanden.
      ich meinte das es alles automatisch geht.
      für die user die sich anmelden.

      Kommentar


      • #4
        Wohl nicht verstanden.
        Dann scripte es so.
        openSuSE - linux for open minds

        Kommentar


        • #5
          Wie gesagt ich bin noch ein Anfänger und weiß nicht wie ich es schreiben soll.

          Kommentar


          • #6
            Dann lerne die Grundlagen.

            Glaube kaum das es dir einer fertig schreibt.
            openSuSE - linux for open minds

            Kommentar


            • #7
              Na dann schau in die DB ob der User schon vorhanden ist und die Passwörter musst du dann schon vergleichen.
              auf PHP/MySQL: du haust nen select raus, um zu schaun obs den username schon gibt also iwas mit WHERE username = 'übergebenerUsername'... die zweite abfrage is ne simple php-if-abfrage:
              PHP-Code:
              if($password1 == $password2dosomething(); 
              "2 hours of trial and error can save 10 minutes of manual reading."

              Kommentar


              • #8
                Ich finde du hast das Script viel zu umständlich gelöst es ginge 100 mal einfacher.

                Kommentar


                • #9
                  natürlich, aber erstmal gehts ihm wahrscheinlich darum, seinen login zu haben, das er funktioniert.
                  "2 hours of trial and error can save 10 minutes of manual reading."

                  Kommentar


                  • #10
                    Nein, das Problem ist, dass das Script auch nicht von ihm ist. Und des weiteren auch auf alte Standards setzt, siehe MySQL statt MySQLi etc. Sieht mir eher nach einem alten Tutorial Script aus.
                    openSuSE - linux for open minds

                    Kommentar


                    • #11
                      PHP-Code:
                          $username mysql_real_escape_string($_POST['username']);
                          
                          
                      //quick/simple validation
                          
                      if(empty($username)){ $action['result'] = 'error'array_push($text,'You forgot your username'); } 
                      Die Prüfung kommt viel zu spät, wenn Du oben schon filterst
                      [COLOR="#F5F5FF"]--[/COLOR]
                      [COLOR="Gray"][SIZE="6"][FONT="Georgia"][B]^^ O.O[/B][/FONT] [/SIZE]
                      „Emoticons machen einen Beitrag etwas freundlicher. Deine wirken zwar fachlich richtig sein, aber meist ziemlich uninteressant.
                      [URL="http://www.php.de/javascript-ajax-und-mehr/107400-draggable-sorttable-setattribute.html#post788799"][B]Wenn man nur Text sieht, haben viele junge Entwickler keine interesse, diese stumpfen Texte zu lesen.“[/B][/URL][/COLOR]
                      [COLOR="#F5F5FF"]
                      --[/COLOR]

                      Kommentar

                      Lädt...
                      X