Results 1 to 10 of 10

Thread: delete user from .htpassword file

  1. #1
    Life is a dick and when itīs get hard---just fuck it... DEVELISH's Avatar
    Join Date
    Jul 2005
    Posts
    2,367

    delete user from .htpassword file

    Hi,

    i need to delete a user from the .htpassword file - no, not by hand but by a programm (shell script or php or something)

    my htpasswd command does not support the "-D" for deleting a user.

    anybody have an idea?

    THANKS ;D

    DEVELISH


  2. #2
    virgin by request ;) Chilihost's Avatar
    Join Date
    Oct 2003
    Posts
    4,496
    .htpasswd is just a text file, you can edit it in notepad or directly on the server with a text editor like vi. The other way you can edit it is through your billing company's script.

    cheers,
    Luke


  3. #3
    Life is a dick and when itīs get hard---just fuck it... DEVELISH's Avatar
    Join Date
    Jul 2005
    Posts
    2,367

    I Wonder?

    Hehe, that's too easy

    I did programm something myself to add users

    <?php
    [...]
    exec ('htpasswd and more code to add user');
    [...]
    ?>

    now I need to delete one single user from the .htpasswd file


    the command to do this is "htpasswd -D .htpasswd username" but my htpasswd command does not support the -D option

    I'd like to do something like this



    Code:
    #!/bin/bash
    
    users=`cat /path/to/.htpasswd`
    
    $searchFor =`cat /path/to/.htpasswd | grep $1`
    
    for Name in $users
    do
    #if $name is not the username to be deleted write to a tmp file
    if [$Name != $searchFor]
    write $name to /path/to/htpasswd.tmp
    fi
    done
    mv /path/to/htpasswd.tmp /path/to/.htpasswd
    done
    so I can call the script with
    $ ./script.sh username


    Develish ;D


  4. #4
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    i wrote a real quick simple perl script that will do what you're looking for. use this at your own risk, as i didn't have the time to debug/test it.

    you can run it via the command line: perl scriptname.pl username


    Code:
    #!/usr/bin/perl
    
    
    $password_file = '/path/to/.htpasswd';
    
    
    
    $username_to_delete = $ARGV[0];
    
    
    
    open(F,"$password_file") || die "$!";
    
    while(<F>) {
    
    chomp;
    ($u,$p) = split /\:/,$_;
    
    
    push (@logins,$_) unless ($u eq $username_to_delete);
    
    
    }
    
    
    close(F);
    
    
    
    open(F,">$password_file") || die "$!";
    
    
    foreach (@logins) {
    
    print F "$_\n";
    
    }
    
    
    close(F);
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  5. #5
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    not sure why it didn't come through, but the "while" line should be:

    Code:
    while(<F>) {
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  6. #6
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    ok...it's not liking that..let's try this:

    while(&lt;F&gt {
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  7. #7
    Life is a dick and when itīs get hard---just fuck it... DEVELISH's Avatar
    Join Date
    Jul 2005
    Posts
    2,367
    cool, thanks hagan

    now I can complete my user management


  8. #8
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    Quote Originally Posted by DEVELISH
    cool, thanks hagan

    now I can complete my user management

    wow..i'm surprised that it actually worked!!
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


  9. #9
    Life is a dick and when itīs get hard---just fuck it... DEVELISH's Avatar
    Join Date
    Jul 2005
    Posts
    2,367
    Oh, that I don't know yet,

    I copied the code but have not tested it yet - will do it within the next couple of hours ;D

    DEVELISH


  10. #10
    I'm a farmhand on your dad's rooster ranch. haganxy's Avatar
    Join Date
    Dec 2004
    Location
    Seattle, WA
    Posts
    379
    hehehe....ok!
    hagan - IT nerd
    PrideBucks.com
    ICQ: 49962103


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •