Created
February 26, 2021 08:33
-
-
Save ChatchaiJ/5034105008d9c5817d1a3d575f332b95 to your computer and use it in GitHub Desktop.
Change user password of a user in grafana sqlite3 db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w- | |
use strict; | |
use warnings; | |
use Crypt::PBKDF2; # libcrypt-pbkdf2-perl | |
use String::Random qw(random_string); # libstring-random-perl | |
use constant HASHCLASS => 'HMACSHA2'; | |
use constant ITERATION => 10000; | |
use constant OUTPUTLEN => 50; | |
die "Usage: $0 login password\n" unless defined $ARGV[1]; | |
my $login = $ARGV[0]; | |
my $pass = $ARGV[1]; | |
my $salt = random_string("ssssssssss"); | |
my $pbkdf2 = Crypt::PBKDF2->new( | |
hash_class => HASHCLASS, | |
iterations => ITERATION, | |
output_len => OUTPUTLEN, | |
); | |
my $hash = $pbkdf2->PBKDF2_hex($salt, $pass); | |
print "# salt = $salt\n"; | |
print "# password = $hash\n"; | |
print << "EOT"; | |
echo "update user set password = '$hash', salt = '$salt' where login = '$login';" | sudo sqlite3 /var/lib/grafana/grafana.db | |
EOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment