Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created February 26, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChatchaiJ/5034105008d9c5817d1a3d575f332b95 to your computer and use it in GitHub Desktop.
Save ChatchaiJ/5034105008d9c5817d1a3d575f332b95 to your computer and use it in GitHub Desktop.
Change user password of a user in grafana sqlite3 db
#!/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