]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 250897: Enforce a 10 minute waiting period between password reset attempts to...
authorjustdave%bugzilla.org <>
Mon, 25 Oct 2004 14:13:27 +0000 (14:13 +0000)
committerjustdave%bugzilla.org <>
Mon, 25 Oct 2004 14:13:27 +0000 (14:13 +0000)
 submitted multiple times.
Patch by Joel Peshkin <bugreport@peshkin.net>
r=kiko, a=justdave

Bugzilla/Token.pm
template/en/default/global/user-error.html.tmpl

index d7d326ccca63748d828e3a3db3d1a5be8e85eb7c..55362d18473e67fadb993d008677631710c9d1f9 100644 (file)
@@ -116,11 +116,19 @@ sub IssuePasswordToken {
 
     # Retrieve the user's ID from the database.
     my $quotedloginname = &::SqlQuote($loginname);
-    &::SendSQL("SELECT userid FROM profiles WHERE login_name = $quotedloginname");
-    my ($userid) = &::FetchSQLData();
+    &::SendSQL("SELECT profiles.userid, tokens.issuedate FROM profiles 
+                    LEFT JOIN tokens
+                    ON tokens.userid = profiles.userid
+                    AND tokens.tokentype = 'password'
+                    AND tokens.issuedate > DATE_SUB(NOW(), INTERVAL 10 MINUTE)
+                    WHERE login_name = $quotedloginname");
+    my ($userid, $toosoon) = &::FetchSQLData();
+
+    if ($toosoon) {
+        ThrowUserError('too_soon_for_new_token');
+    };
 
     my $token_ts = time();
-    my $issuedate = time2str("%Y-%m-%d %H:%M", $token_ts);
 
     # Generate a unique token and insert it into the tokens table.
     # We have to lock the tokens table before generating the token, 
@@ -130,7 +138,7 @@ sub IssuePasswordToken {
     my $quotedtoken = &::SqlQuote($token);
     my $quotedipaddr = &::SqlQuote($::ENV{'REMOTE_ADDR'});
     &::SendSQL("INSERT INTO tokens ( userid , issuedate , token , tokentype , eventdata )
-                VALUES      ( $userid , '$issuedate' , $quotedtoken , 'password' , $quotedipaddr )");
+                VALUES      ( $userid , NOW() , $quotedtoken , 'password' , $quotedipaddr )");
     &::SendSQL("UNLOCK TABLES");
 
     # Mail the user the token along with instructions for using it.
index 040cc81b57a0ad6444c8b8b04cd97a18c981a048..83964ad036e31e17d9c46cca7aeb545a158dbac7 100644 (file)
     The token you submitted does not exist, has expired, or has
     been cancelled.
 
+  [% ELSIF error == "too_soon_for_new_token" %]
+    [% title = "Too Soon For New Token" %]
+    You have requested a password token too recently to request
+    another.  Please wait a while and try again.
+
   [% ELSIF error == "unknown_keyword" %]
     [% title = "Unknown Keyword" %]
     <code>[% keyword FILTER html %]</code> is not a known keyword.