waynew Posted September 24, 2009 Share Posted September 24, 2009 I have a text file of usernames and encrypted passwords (this is a college assignment that I'm working on - no funny stuff). The text file looks like this: wwuser1, rexrms/F3P1D2 wwuser2, stq/WqYkSonuQ wwuser3, maslN9sW1ynog wwuser4, syo.HWp6snVw6 wwuser5, exVAke3EE.HYw wwuser6, trmGMnhO6XOjw wwuser7, haybU2Bmy02BE wwuser8, unJE7ALfHZRKo wwuser9, coRe3NYe2UJc. wwuser10, rubou4spJ8aQA What I have to do: Explode the overall string from the text file by newline. Which will give me ten sep. lines (all of which are located in an array via means of explode("\n"). That's fine and working well. However the problem is that the 10th line has an extra space. The salt of each password is the first two characters of the actual pass. So for rexrms/F3P1D2, the salt is re. I'm pretty sure that the extra space on wwuser10 is apart of the salt; as it's the only password I can't crack. I've been using trim() to get rid of the white space around the passwords, so this white space is being trimmed. How can I get rid of only two white spaces per line? Quote Link to comment https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/ Share on other sites More sharing options...
waynew Posted September 24, 2009 Author Share Posted September 24, 2009 By the way my code for reading in and sorting out the text file is: <?php /*************************************** READ IN STUDENT PASSWORDS FILE ***************************************/ //name of password file to use $password_file = "ww.txt"; //open password file $fh = fopen($password_file, 'r'); //read data from file into string called $password_data $password_data = fread($fh,filesize($password_file)); //close the file fclose($fh); //create an array called passwords_newlines //by splitting up (explode) each word that is separated //by a newline into their own indexes in an array $passwords_newlines = explode("\n",$password_data); $index = 0; $usernames = array(); $enc_passwords = array(); $salt = array(); //then loop through that array and split each line //up by exploding the string based on the comma //also get rid of whitespace before and after //by using trim() foreach($passwords_newlines as $password_line){ list($u,$p) = explode(",",trim($password_line)); $usernames[$index] = trim($u); $enc_passwords[$index] = trim($p); //get salt $salts[$index] = substr($enc_passwords[$index],0,2); $index++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/#findComment-923996 Share on other sites More sharing options...
Garethp Posted September 24, 2009 Share Posted September 24, 2009 Well, rather than using trim, why don't you use explode(", ", $password_line); Quote Link to comment https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/#findComment-923998 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 However the problem is that the 10th line has an extra spaceNo. It doesn't. The leading 'r' is under the 2nd character in the line above it because 10 in wwuser10 has one more character than all the other lines above it. Quote Link to comment https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/#findComment-923999 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 Running your code and dumping the $salts array gives the correct values - Array ( [0] => re [1] => st [2] => ma [3] => sy [4] => ex [5] => tr [6] => ha [7] => un [8] => co [9] => ru ) Quote Link to comment https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/#findComment-924002 Share on other sites More sharing options...
waynew Posted September 24, 2009 Author Share Posted September 24, 2009 Thanks for the replies. STupid mistake on my part; I wasn't at the class where this project was handed out so I completely misunderstood what everyone meant by "the extra white space". Found the problem. It wasn't printing out the last cracked password. Max execution time was at ten seconds. Tried it on another host and it worked fine. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/175329-solved-text-file-problem/#findComment-924047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.