Page MenuHomePhabricator

createAndPromote.patch

Authored By
bzimport
Nov 21 2014, 10:40 PM
Size
1 KB
Referenced Files
None
Subscribers
None

createAndPromote.patch

Index: createAndPromote.php
===================================================================
--- createAndPromote.php (revision 50834)
+++ createAndPromote.php (working copy)
@@ -24,18 +24,28 @@
$username = $args[0];
$password = $args[1];
-echo( wfWikiID() . ": Creating and promoting User:{$username}..." );
+echo( wfWikiID() . ": Creating and promoting User:{$username}...\n" );
# Validate username and check it doesn't exist
$user = User::newFromName( $username );
if( !is_object( $user ) ) {
- echo( "invalid username.\n" );
+ echo( "$username is not a valid username.\n" );
die( 1 );
} elseif( 0 != $user->idForName() ) {
- echo( "account exists.\n" );
+ echo( "An account called $username already exists.\n" );
die( 1 );
}
+# Validate password
+if( strlen( $password ) < $wgMinimalPasswordLength) {
+ echo( "The password is too short. It must be at least $wgMinimalPasswordLength characters (\$wgMinimalPasswordLength).\n");
+ die( 1 );
+}
+if( $wgContLang->lc( $password ) === $wgContLang->lc( $username ) ) {
+ echo( "The password cannot be the same as the username.\n" );
+ die( 1 );
+}
+
# Insert the account into the database
$user->addToDatabase();
$user->setPassword( $password );
@@ -50,7 +60,7 @@
$ssu = new SiteStatsUpdate( 0, 0, 0, 0, 1 );
$ssu->doUpdate();
-echo( "done.\n" );
+echo( "User:{$username} successfully created.\n" );
function showHelp() {
echo( <<<EOT

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5335
Default Alt Text
createAndPromote.patch (1 KB)

Event Timeline