htaccess passwörter verwalten

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

  • htaccess passwörter verwalten

    ich hab ein vezeichnis mit .htaccess geschützt.

    die user und die passwörter stehen wie fast immer in einer .htpasswd datei.
    Wie kann ich mit PHP machen, dass ich ein Passwort von einem user ändern kann?

    die htpasswd sieht ja so aus

    user1:cryptedpw
    user2:cryptedpw
    user3:cryptedpw

    wie kann ich jetzt zum beispiel das passwort von user2 ändern?

    muss ich das teil per fopen öffnen?! und wie weiter?
    Zuletzt geändert von Moqui; 01.02.2003, 10:57.
    tata
    moqui

    [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

  • #2
    theoretisch könntest du das öffnen und neu schreiben.
    du musst das pw eben nur verschlüsseln.

    das beste ist, wenn du das proggi zum pw setzen/ändern/neu als systembefehlt ausführst.

    wenn es linux ist, findest du das ding unter
    /usr/bin/htpasswd

    Code:
    [b].... # /usr/bin/htpasswd --help[/b]
    
    Usage:
            htpasswd [-cmdps] passwordfile username
            htpasswd -b[cmdps] passwordfile username password
    
            htpasswd -n[mdps] username
            htpasswd -nb[mdps] username password
     -c  Create a new file.
     -n  Don't update file; display results on stdout.
     -m  Force MD5 encryption of the password.
     -d  Force CRYPT encryption of the password (default).
     -p  Do not encrypt the password (plaintext).
     -s  Force SHA encryption of the password.
     -b  Use the password from the command line rather than prompting for it.
    On Windows, TPF and NetWare systems the '-m' flag is used by default.
    On all other systems, the '-p' flag will probably not work.
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar


    • #3
      ja aber

      also öffnen und neu schreiben

      das klingt logisch

      ABER: wie lösche ich die Zeile raus, inder der Benutzer definiert wurde?

      gibts ein befehl, der eine Zeile löscht, in der ein bestimmter String vorkommt?
      tata
      moqui

      [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

      Kommentar


      • #4
        die datei liest du ja mit file() ein, nehme ich mal an. da kommst dann ein array raus. jetzt brauchst du nur den arrayindex zu löschen, wo der user fott soll.

        dann das array (zeilenweise) wieder in die datei schreiben. beim ändern des pws machst du das ja mal ähnlich. oder?
        INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


        Kommentar


        • #5
          PHP-Code:
          function change_pw($htpasswd,$username,$newpass)
          {
              
          $datei=file($htpasswd);
              
          $eintraege=count($datei);
              for (
          $i=0;$i<$eintraege;$i++)
              {
                  
          $eintrag=explode(':',$datei[$i]);
                  if (!
          strtolower($eintrag[0])==strtolower($username))
                      continue;
                  
          $salt=substr($eintrag[1],0,2);
                  
          $eintrag[1]=crypt($newpass,$salt);
                  
          $datei[$i]=implode(':',$eintrag);
                  break;
              }
              
          $fp=fopen($htpasswd,'wb');
              
          fwrite($fp,implode('\n',$datei));
              
          flocse($fp);

          sollte gehen
          Ich denke, also bin ich. - Einige sind trotzdem...

          Kommentar


          • #6
            thx

            ich liebe dieses Forum

            danke jetzt war ich 10 mins online und hab meine antworten.

            thx
            tata
            moqui

            [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

            Kommentar


            • #7
              eins noch

              der lerneffekt war bei mir == 0;

              kann mir mal jemand das script erklären, ich kenn die funktionen garnet, z. B. strtolower() <-- sagt mir garnix

              mein WeaverSlave sagt "Make a string lowercase" <-- sagt mir aber auch nix

              und wenn ichs richtig verstanden hab liest file() eine Datei zeilenweise?! ich kannte bis jetzt nur fread und freads...
              tata
              moqui

              [COLOR=red]Ich will keine unaufgeforderten Mails über PHP Fragen. Es gibt ein Forum hier! Und ich bin nicht Scripter für jeden, der mir ne Mail schreibt![/COLOR]

              Kommentar


              • #8
                file() liest dir die datei in ein array ein. jeder index ist eine zeile der datei.

                strtolower() - Make a string lowercase - mache alle buchstaben klein.
                INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                Kommentar


                • #9
                  nochmal zum ausführlichen nachlesen....

                  file()
                  http://de.php.net/manual/de/function.file.php

                  strtolower()
                  http://de.php.net/manual/de/function.strtolower.php

                  das php.net kann ich dir nur empfehlen

                  http://de.php.net/manual/de/
                  INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                  Kommentar


                  • #10
                    @Abraxax
                    Du bist zu gut für diese Welt
                    Ich denke, also bin ich. - Einige sind trotzdem...

                    Kommentar


                    • #11
                      @happy.
                      du aber auch...
                      INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                      Kommentar

                      Lädt...
                      X