diff --git a/bin/account-manager.pl.in b/bin/account-manager.pl.in
index 1364137b2f924c6d6fe9fbaf4943f07f180fd49c..4356bf1a1a95d8edafe0c38e0b0ce33ed7a380f1 100755
--- a/bin/account-manager.pl.in
+++ b/bin/account-manager.pl.in
@@ -9,6 +9,7 @@ no warnings 'experimental::smartmatch';
 
 use Config::Tiny;
 use Data::Dumper;
+use DateTime;
 use English qw(-no_match_vars);
 use Getopt::Long qw(:config auto_help);
 use Log::Any::Adapter;
@@ -86,23 +87,28 @@ sub add_account {
         -verbose => 0
     ) unless $options{sp_entityid};
 
-    my $test_account = IdPAccountManager::TestAccount->new(
-        db          => $db,
-        profile     => $options{profile},
-        sp_entityid => $options{sp_entityid},
-        scope       => $configuration->{idp}->{scope},
-    );
-
     my $entity = $options{sp_entityid};
     my $validity_period =
         $configuration->{$entity}->{account_validity_period} ||
         $configuration->{service}->{account_validity_period};
+    my $password = IdPAccountManager::Tools::generate_password();
+
+    my $account = IdPAccountManager::TestAccount->new(
+        db              => $db,
+        profile         => $options{profile},
+        sp_entityid     => $options{sp_entityid},
+        scope           => $configuration->{idp}->{scope},
+        password        => $password,
+        password_hash   => IdPAccountManager::Tools::sha256_hash($password),
+        creation_date   => DateTime->today(),
+        expiration_date => DateTime->today()->add(days => $validity_period)
+    );
 
     die "Failed to save test account\n"
-        unless $test_account->save(accounts_validity_period => $validity_period);
+        unless $account->save();
 
     printf "Account created:\n\tuserid: user%d\n\tpassword: %s\n",
-      $test_account->id(), $test_account->password();
+      $account->id(), $account->password();
 
 }
 
diff --git a/lib/IdPAccountManager/TestAccount.pm b/lib/IdPAccountManager/TestAccount.pm
index f089dafe94b71c96f92eaae6e7a38c98a97c5ae7..3f6c9c8438496a6c0578c16ccd55aacb4472ebcc 100644
--- a/lib/IdPAccountManager/TestAccount.pm
+++ b/lib/IdPAccountManager/TestAccount.pm
@@ -5,8 +5,6 @@ use warnings;
 
 use base 'IdPAccountManager::DB::Object';
 
-use DateTime;
-
 __PACKAGE__->meta->setup(
     table   => 'testaccounts',
 
@@ -126,24 +124,6 @@ sub print {
       $self->expiration_date()->strftime('%Y:%m:%d');
 }
 
-sub save {
-    my ($self, %args) = @_;
-
-    # If no ID is defined, it is a new account
-    if (! defined $self->id()) {
-        $self->password(
-            IdPAccountManager::Tools::generate_password());
-        $self->password_hash(
-            IdPAccountManager::Tools::sha256_hash($self->password()));
-        $self->creation_date(DateTime->today());
-        $self->expiration_date(
-            DateTime->today()->add(days => $args{accounts_validity_period})
-        );
-    }
-
-    $self->SUPER::save();
-}
-
 sub internal_uid {
     my ($self) = @_;
     return 'user' . $self->id();
diff --git a/lib/IdPAccountManager/WebRequest.pm b/lib/IdPAccountManager/WebRequest.pm
index 34701388380dc5e2dcedf56343c1d774f964ded2..7b40270ae99a3a27b64a73e513e2043c119bf100 100644
--- a/lib/IdPAccountManager/WebRequest.pm
+++ b/lib/IdPAccountManager/WebRequest.pm
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use CGI;
+use DateTime;
 use English qw(-no_match_vars);
 use Template;
 use Log::Any::Adapter;
@@ -463,13 +464,18 @@ sub req_validate_token {
         $self->{configuration}->{service}->{account_validity_period};
 
     foreach my $profile (split(/, */, $profiles)) {
+        my $password = IdPAccountManager::Tools::generate_password();
         my $account = IdPAccountManager::TestAccount->new(
-            db          => $self->{db},
-            profile     => $profile,
-            sp_entityid => $entity,
-            scope       => $self->{configuration}->{idp}->{scope},
+            db              => $self->{db},
+            profile         => $profile,
+            sp_entityid     => $entity,
+            scope           => $self->{configuration}->{idp}->{scope},
+            password        => $password,
+            password_hash   => IdPAccountManager::Tools::sha256_hash($password),
+            creation_date   => DateTime->today(),
+            expiration_date => DateTime->today()->add(days => $validity_period)
         );
-        next unless $account->save(accounts_validity_period => $validity_period);
+        next unless $account->save();
         push @accounts, $account;
     }