We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12241
    • 80 Posts
    I need your help please. (I’ve searched forums/google with little luck)

    Problem:
    User has to enter their password twice. First, to log in. Second, to verify on ’change password’ page.

    Concept:
    When a webuser registers (via WebLoginPE) they are sent a verification email with a randomly generated password. When the user clicks the link in email they are taken to a login page which, after logging in, directs to a custom ’change password’ page (via WebChangePwd) this is so that my new users can change their password right away, rather than having to go into the ’Profile’ and scroll to the bottom to enter a new password.


    Possible work around:
    Rather than having my users re-enter their temporary password I thought it would really nice for that ’old password’ input field to be automagically filled out for them upon logging in.

    What I’m trying:
    I took the phx custom modifier [+phx:post=`password`+] and threw that into the ’value’ attribute of the ’oldpassword’ input in the ’change password’ form template... when I test it out the text input field looks like it contains the password, as in it contains the right amount of characters, but when I try to submit the change password form it says that the old password is incorrect. I’ve tested the phx:post modifier with the `username` variable and that does not work either so I’m guessing it is something to do with the way the usernames / passwords are stored for security either with MODx or with WebLoginPE (since that is the snippet processing the login form)?

    How can I get this done?

    Thanks in advance, this is my first attempt at setting up a log in system with modx and me and php are still in the early phases of our relationship, hence this post:) Below is my current setup:

    host:
    localhost
    php5
    mysql

    modx version:
    evo 1.0.4

    snippets:
    WebLoginPE 1.3.1
    WebChangePwd 1.0

    plugins:
    PHx 2.1.4



      Environment:
      modx: rev 2.0.8-pl
      localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
      • 12241
      • 80 Posts
      Okay, so the session variable ’webValid’ contains the users password encoded in base64, at least that is what I can tell from poking around:

          $_SESSION['webValid']=base64_encode($givenPassword);


      Found at line 339 in weblogin.processor.inc.php

      So my guess is that I have to write a snippet that will grab this session variable and decode it from base64 and have it fill a placeholder? Does that sound right? If anyone wants to figure this out for me that would be awesome grin or just a hint is fine, until then I’ll fumble around with it.
        Environment:
        modx: rev 2.0.8-pl
        localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Wouldn’t it be a better idea for the user to have to enter his old password? What if somebody else gets ahold of that email? I’ve never experienced any site that has the old password already entered.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          What you’re describing is technically impossible on any decent login system. Passwords should be stored hashed. That’s one-way encryption. You cannot de-crypt it and use it to pre-populate a form. That’s really the point of having it as a password: it cannot be easily hacked. The way passwords get cracked in a brute force hack (for example) is that a script iterates through thousands of dictionary words and then compares the hashed result to the hash of the password. If the hashes match, then the passwords must match.

          If you pre-populate a form with a password, you site will be HORRIBLY insecure. Someone could read the password right from the HTML. You would fail any security audit. It’s a horrible idea, even if it’s possible, and again, it would only be possible if you had a password storage mechanism that stored the password in plain-text -- which is hardly a password storage system... if it’s plaintext it’s more of a toy. MODx stores users’ passwords hashed.

          What’s typically done in these types of work-flows is that the system emails the user a "temporary password". Usually, the system doesn’t actually change the password right away. Instead it generates a special unique link where the user can click within a certain time frame (say within 30 minutes). If the user never clicks it, or clicks it too late, then nothing happens. If they do click it, the user then must enter in secondary validation, e.g. your pet’s name, or your best friend from High school or one of those other security questions. These are typically stored just like passwords: the answers are hashed, so there’s no way for the system to re-populate a form with their values. If the user’s response to the question is valid, only then does the system wipe the existing password and regenerate a new one.

          That’s a lengthy explanation that goes beyond what you’re asking, but hopefully it will help you know why you aren’t finding many answers to this particular question. I haven’t dealt with WebLoginPE for a while, but I wrote a lot of the documentation on it on the old wiki after struggling with scenarios like this...
            • 12241
            • 80 Posts
            Wouldn’t it be a better idea for the user to have to enter his old password?

            It seemed to redundant. I like the way the reset password function works in Weblogin / WebloginPE better, for example, you get an email with an activation password and a link to the activation form which contains three inputs: Activation password; New Password; Confirm New Password; and then you hit the activate button and presto you’ve just did what I’m basically trying to accomplish for new registered users. The default behavior, for WebLoginPE, just let’s the user log in with the random password and then nothing... the user has to go through effort of figuring out where the ’change password’ function is and I know what will happen, these people will not change their password and then they’ll be calling me because they lost their passwords and blah. Wouldn’t it be easier for the user to just login and then be prompted with the password change form so that they can do it while it’s fresh. Just trying make it feel right.
              Environment:
              modx: rev 2.0.8-pl
              localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
              • 12241
              • 80 Posts
              What you’re describing is technically impossible on any decent login system.
              It’s the experience I’m going after, I don’t really want to do the password thingy like I am, it’s just that is the way the WebChangePwd snippet is setup and like I said, I’m still getting used to people rolling their eyes at me when I talk about php (aka I’m new)

              If you pre-populate a form with a password, you site will be HORRIBLY insecure.
              Yeah, I figured I was a little off base... or... actually a lot:) But hey it seemed like a good idea at that particular moment.

              What’s typically done in these types of work-flows is that the system emails the user a "temporary password". Usually, the system doesn’t actually change the password right away. Instead it generates a special unique link where the user can click within a certain time frame (say within 30 minutes). If the user never clicks it, or clicks it too late, then nothing happens. If they do click it, the user then must enter in secondary validation, e.g. your pet’s name, or your best friend from High school or one of those other security questions. These are typically stored just like passwords: the answers are hashed, so there’s no way for the system to re-populate a form with their values. If the user’s response to the question is valid, only then does the system wipe the existing password and regenerate a new one.
              This is really informative, thanks!
                Environment:
                modx: rev 2.0.8-pl
                localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37
                • 12241
                • 80 Posts
                Okay, got it. No, I’m not hacking the password, that is dumb... real dumb. Here is what I did thanks to the real smart WebLoginPE:

                If you have your registration type set to ’Verify’ then the users password is sent to their email with a link to log in. This auto generated password is ugly and not memorable so I wanted to prompt my new users with a simple password change on their first log in. Here’s how I accomplished my goal.


                I changed the link in the verification email to point to a document with a custom login form. To change the link I edited weblogin.class.php around line 694:

                $siteURL = $modx->config['site_url'];

                and ADDED directly below:
                $siteURL .= 'index.php?id=47';//doc id for custom change password page (remove line for default login)


                So the user registers, gets email with random password, clicks custom link and is brought to my custom login call:
                [!WebLoginPE? &liHomeId=`51` &loHomeId=`33` &loginFormTpl=`wlpe.login.activate`!]

                &loginFormTpl=wlpe.login.activate
                <h2>[*longtitle*]</h2>
                <p>[*introtext*]</p>
                [+wlpe.message+]
                <div id="wlpeLogin">
                	<form id="wlpeLoginForm" action="[~[*id*]~]" method="post">
                		<fieldset id="wlpeLoginFieldset">
                			<legend id="wlpeLegend"></legend>
                			<label id="wlpeUsernameLabel" for="wlpeUsername">Username
                				<input id="wlpeUsername" type="text" name="username" />
                			</label>
                			
                			<label id="wlpePasswordLabel" for="wlpePassword">Password
                				<input id="wlpePassword" type="password" name="password" />
                			</label>
                						
                		</fieldset>
                		<fieldset id="wlpeLoginButtons">
                			<button type="submit" id="wlpeLoginButton" name="service" value="login">Activate Account</button>
                
                		</fieldset>
                	</form>
                </div>

                Just a very simplified version of the regular log in but instead of going to the default profile view the user is brought to my custom change password page via the &liHomeId=`51` parameter. This allows me to put another custom snippet call for my quick password change:
                [!WebLoginPE? &type=`profile` &loHomeId=`33` &profileTpl=`wlpe.profile.password` !]			

                Now, instead of pulling up the normal profile edit form, I created a custom profile template, assigned via &profileTpl parameter. The custom template was basically just going to be the change password section of the normal profile page, however, if I did not include the other inputs (for all the other user attributes) then those values would be deleted/overwritten. So I just left all of the default input tags in the custom template and changed their ’type` to `type=hidden`, I then wrapped those sections of the code in a div and set it to display:none so that only the change password section shows up. It works, sweet!
                &profileTpl=wlpe.profile.password
                <h2>New Password</h2>
                [+wlpe.message+]
                <div id="wlpeUser">
                	<form enctype="multipart/form-data" id="wlpeUserProfileForm" action="[~[*id*]~]" method="POST">
                		<fieldset id="wlpeUserProfileInput">
                			<div id="wlpeUserInfo">
                				<h3 id="wlpeProfileWelcome">Hello [+user.fullname+] ([+user.username+])!</h3>
                				<p id="wlpeProfileInfo" class="info">[+introtext+]</p>
                			</div>
                		
                			<fieldset id="wlpeNewPasswordArea">
                				<legend id="wlpeNewPasswordAreaLegend"></legend>
                				<p id="wlpeNewPasswordInfo"><strong style="color: SkyBlue">Create your password</strong> <br /><span class="info">(the default password for your account was sent to you in the registration verification email. Leave this form blank to keep that as your password or choose something easier to remember, it's up to you.</span></p>
                
                				<label for="wlpeUserProfilePassword">New Password
                				<input id="wlpeUserProfilePassword" type="password" name="password" value="" />
                				</label>
                
                				<label for="wlpeUserProfilePasswordConfirm">New Password (confirm)
                				<input id="wlpeUserProfilePasswordConfirm" type="password" name="password.confirm" value="" />
                				</label>
                			</fieldset>
                			
                			<div style="display:none;"><!-- section needed so values do NOT get erased from database on save -->
                			
                							<input id="wlpeUserProfileFullName" type="hidden" name="fullname" value="[+user.fullname+]" />
                							<input id="wlpeUserProfileEmail" type="hidden" name="email" value="[+user.email+]" />
                							<input id="wlpeUserProfilePhone" type="hidden" name="phone" value="[+user.phone+]" />
                							<input id="wlpeUserProfileMobile" type="hidden" name="mobilephone" value="[+user.mobilephone+]" />
                							<input id="wlpeUserProfileFax" type="hidden" name="fax" value="[+user.fax+]" />
                							<input id="wlpeUserProfileMailingAddress" type="hidden" name="mailingaddress" value="[+user.mailingaddress+]" />
                							<input id="wlpeUserProfileLot" type="hidden" name="lot" value="[+user.lot+]" />
                							
                							<input id="wlpeUserProfileState" type="hidden" name="state" value="[+user.state+]" />
                							<input id="wlpeUserProfileZip" type="hidden" name="zip" value="[+user.zip+]" />
                							[+form.country+]
                							<input id="wlpeUserProfileDob" type="hidden" name="dob" value="[+user.dob+]" />
                							[+form.gender+]
                							<textarea id="wlpeUserProfileComment" name="comment">[+user.comment+]</textarea>
                				
                			</div>
                			
                		</fieldset>
                		<fieldset id="wlpeUserProfileButtons">
                			<button type="submit" id="wlpeSaveProfileButton" name="service" value="saveprofile">Save</button>
                			<button type="submit" id="wlpeProfileDoneButton" name="service" value="cancel">Done</button>
                		</fieldset>
                	</form>
                </div>

                When the user finished changing their password they are brought to the regular default login/profile section. If the user wants to just keep their hard to remember random password then they just click ’done’ button and no password change. It feels better to me to have the system prompt me to change my auto generated password right away. Any ideas about how this could be done more effectively and if there are any security issues I should be aware of would be appreciated. I apologize for starting this post with such a limited question, I should have titled the post "how to direct new users to change their password at login"

                Thanks for teaching me you rock!


                  Environment:
                  modx: rev 2.0.8-pl
                  localhost: Apache/2.0.63 (Unix) PHP/5.2.11 DAV/2, MySQL client version: 5.1.37