Hi,

Is there a hack available which would allow Users to choose their own password, rather then being e-mailed? Through a search I found that this question has been raised before(http://drupal.org/node/view/1959). That post specifies the code which handles the registration process, but does not imply there is a hack.

If there is a hack available, I'd appreciate someone to point me to it. Thanks!

Scott

Comments

jt_medic’s picture

In user.module:

Find (around line 825, but I'd already done a bit of hacking so it might not be exactly there)

function user_register($edit = array())

Then move down a few lines and find

else if (user_deny("user", $edit["name"])) {
      $error = t("The name '%s' has been denied access.", array("%s" => $edit["name"]));
    }

and put under it,

else if ($edit["jtpass1"] != $edit["jtpass2"]) {
			$error = t("The specified passwords do not match.", array("%s" => $edit["jtpass1"]));
		}
		else if (strlen($edit["jtpass1"]) == 0) {
			$error = t("You must enter a password in both boxes.", array("%s" => $edit["jtpass1"]));
		}
		else if (strlen($edit["jtpass2"]) == 0) {
					$error = t("You must enter a password in both boxes", array("%s" => $edit["jtpass2"]));
		}

Find (a bit further down)

if ($success) {

    $from = variable_get("site_mail", ini_get("sendmail_from"));
    $pass = user_password();

and replace it with

if ($success) {

    $from = variable_get("site_mail", ini_get("sendmail_from"));
    $pass = $edit["jtpass1"];

Find (a bit further down again)
// display the registration form
and a bit below that,

$output .= form_textfield(t("E-mail address"), "mail", $edit["mail"], 30, 64, t("Your chosen password and instructions will be sent to this e-mail address, so make sure it is accurate."));

Now, above that, add

$output .= form_item(t("Password"), "<input type=\"password\" name=\"edit[jtpass1]\" size=\"12\" maxlength=\"24\" /> <input type=\"password\" name=\"edit[jtpass2]\" size=\"12\" maxlength=\"24\" />", t("Enter your chosen password twice."));

I don't know if that's the best way of doing this (as I have NO knowledge of writing php code - I've just kinda made it up by looking at the rest of user.module and adapting things), but it works (I've tested it fairly thoroughly).

blackyzero’s picture

I'm using drupal 4.6, also having problem with send mail. I have done follow your instruction, but it seem doesn't match with yours.

When i try to register user, the page register appear the code:

Password:
<input type="password" name="edit[jtpass1]" size="12" maxlength="24" /> <input type="password" name="edit[jtpass2]" size="12" maxlength="24" />

It stay above box email address and below username.

How can i fix it, please help me. Thank you very much,
And if this function as module of drupal, i think that is good function for whom doesn't have local email or complex SMTP configuration.