Text manipulation with awk (generating password hashes)

dennylin93

Aspiring Daemon

Reaction score: 109
Messages: 783

Hi, I'm creating virtual users with MySQL, and I don't know how to generate the hashed versions of the passwords.

input:
Code:
username1       password1
username2       password2
username3       password3
convert.sh:
Code:
#!/bin/sh

INPUT=./input
OUTPUT=./output
AWK=/usr/bin/awk

$AWK '{printf("INSERT INTO `virtual_users` VALUES (NULL, '\''%s'\'', '\''%s'\'');\n", $1, $2)}' $INPUT > $OUTPUT
I need to use $ dovecotpw -s SSHA256 -p password to insert the hashed string into the output, but I don't know if it can be done with awk. Can anyone point me in the right direction? Thanks.
 

vermaden

Son of Beastie

Reaction score: 1,163
Messages: 2,755

@dennylin93

Try like that:
% awk 'BEGIN { system("dovecotpw -s SSHA256 -p password"); }'
 

Alt

Aspiring Daemon

Reaction score: 82
Messages: 726

Seems these awks completely unusable, never liked them :e
So, we can do
cat $INPUT | perl -ne '/^(.*?)[\s\t]+(.*?)$/; printf("insert into test (a, b) values ('%s', '%s')\n", $1, qx/dovecotpw -s SSHA256 -p $2/);'
Or
cat tttt | perl -ne 'split; printf("insert into test (a, b) values (\"%s\", \"%s\")\n", $_[0], qx/dovecotpw -s SSHA256 -p $_[1]/);'
 
OP
OP
D

dennylin93

Aspiring Daemon

Reaction score: 109
Messages: 783

@SirDice: I forgot that MySQL has password functions as well. I'm not sure if they're compatible with Dovecot though, so I'll test them later.

@vermaden: Not really sure how to use awk properly (I'm a beginner right now). I'll stick to Perl for the moment.

@Alt: The command works perfectly.

Thanks again for all the help.
 
Top