1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Email Password Change wihout login in cpanel

Discussion in 'cPanel Developers' started by fumagally, Nov 25, 2009.

  1. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Friends, I would like a permanent solution to a script to change password without email access cpanel.

    I tried the cpanel api but I could not ...

    Could you help me?

    I need a page where the User enter the email address and new password, after which the password is changed ...

    Please help me ... Thank you!
     
  2. SeanStar

    SeanStar New Member

    Joined:
    Dec 2, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I was working tirelessly over this issue for about an hour...
    My forum was set up so that if you donated you got an email and password as you requested - but it was through me... My email users wanted to change there email passwords. Since I was using my own email client script, I didn't want to reveal my hosters crappy webmail function from cpanel, thus I had to make a script to do it without logging into the webmail of cpanel. This is what I got.

    (I searched google for this problem and never found a straight answer, so I had to figure it out myself. This might help other googler's in the future. ;P)

    Code:
    <html>
    <body>
    <form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
    Email:<br />
    <input type="text" name="email" />@example.com<br />
    Password:<br />
    <input type="password" name="pass" /><br />
    New Password:<br />
    <input type="password" name="newpass" /><br />
    <input type="password" name="newpass2" /><br />
    <input type="submit" value="Submit" />
    </form>
    <br />
    <?php
    
    $username = $_POST['email'];
    $password = $_POST['pass'];
    $cpaneldomain = 'example.com';
    $email = $_POST['email'];
    $emaildomain = 'example.com';
    $newpass = $_POST['newpass'];
    
    if($_POST['newpass']=="")
    {
    echo "";
    }
    else if($_POST['newpass']==$_POST['newpass2'])
    {
    echo "New password submitted.";
    @file("http://$username@$emaildomain:$password@$cpaneldomain:2095/webmail/x/mail/dopasswdpop.html?redirectdomain=&email=$email&domain=$emaildomain&password=$newpass");
    }
    else
    {
    echo "The two new password fields must be the same.";
    }
    ?>
    </body>
    </html>
    
    Hope this helps some people with understanding the cpanel api and so forth.

    Thanks.
     
  3. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    not working for me

    you tested in cpanel 11?

    the message "New password submitted." has displayed.. but the passwords not change...
     
  4. MattDees

    MattDees Member
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    412
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Houston, TX
    Fumagally, well this is possible (via a few methods).
    The params for passwdpop are as follows:

    my ( $email, $passwd, $quota, $domain, $quiet ) = @_;

    So, if you wanted to change a user's password (for testemail@cptest.com) via the API you would do the following:

    Code:
    /xml-api/cpanel?
    cpanel_xmlapi_module=Email&
    cpanel_xmlapi_func=passwdpop&
    cpanel_xmlapi_apiversion=1&
    arg-0=testemail&
    arg-1=testing321&
    arg-3=cptest.com
    or via the xml-api class:


    Code:
    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2096);
    $xmlapi->password_auth("testemail@cptest.com", $oldpass);
    $xmlapi->api1_query($account, "Email", "passwdpop", array("testemail", $newpass, 0, "cptest.com"));

    There are other ways to do this.. but this is the only one that has a guarantee of always working. I should also note that in the api1_query I pass a quota of zero. If this is called via the webmail interface, this will not change the quota (this is enforced in the email module).
     
  5. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    help...


    Yeap!! Understand what you said ... could provide a complete script running .. I think you need only 2 files to make it happen ... Am I right? If you can help thank you very much!
     
  6. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Thanks

    WOOOWWWW... agora sim consegui... tive que remover o @ no @file

    e alterar a linha do tema para x3...

    Very thanks SeanStar...

    cPanelMatt.. do you have a complete script with api?
     
  7. MattDees

    MattDees Member
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    412
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Houston, TX
  8. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
  9. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    try

    cPanelMatt >>> I tried so:

    PHP:
    <?
    include(
    "xmlapi.php");

    $ip "XXXXX";


    $email_completo "teste@uaiinformatica.com.br";
    $oldpass "XXXX";
    $newpass "XXXX";


    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2096);
    $xmlapi->password_auth($email_completo$oldpass);
    print 
    $xmlapi->api1_query($account"Email""passwdpop", array("teste"$newpass0"uaiinformatica.com.br"));
    ?>

    BUT... NOT SUCESSS... ANYONE MESSAGE HAS DISPLAYED...
     
  10. cyon

    cyon Member

    Joined:
    Jan 15, 2003
    Messages:
    322
    Likes Received:
    0
    Trophy Points:
    16
    Try to replace $account with your emailadress. The reason you don't see any printed character is, because the $xmlapi->api1_query returns a SimpleXML-Object -> PHP: SimpleXML - Manual
    You can do
    PHP:
    var_dump($xmlapi->api1_query($account"Email""passwdpop", array("teste"$newpass0"uaiinformatica.com.br")));
    If you do this, you'll see, that the 'result' Value is empty. If you try to change the password by using the direct url mentioned by cPanelMatt you'll also get an XML response, where the 'result' tag is empty.
    For that, if you get a empty result and no error, your password is changed correctly.
     
  11. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    sucess!

    view post bellow ::::
     
    #12 fumagally, Dec 4, 2009
    Last edited: Dec 4, 2009
  12. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    idea

    HOW TO DISPLAY A MESSAGE IN THE PAGE??

    I have an idea .... can do as follows:

    PHP:
    <?
    include(
    "xmlapi.php");

    $ip "***************";


    $email_user "teste@uaiinformatica.com.br";
    $oldpass "**********";
    $newpass "**********";


    $xmlapi = new xmlapi($ip);
    $xmlapi->set_port(2096);
    $xmlapi->password_auth($email_user$oldpass);

    if (***
    HOW TO GET password_auth SUCESS????****) {
    $xmlapi->api1_query($email_user"Email""passwdpop", array("teste"$newpass0"uaiinformatica.com.br"));
    print 
    "Password changed!!!";
    }
    else {
    print 
    "OLD PASSWORD INCORRECT!";
    }

    ?>
    HOW TO GET password_auth SUCESS????
     
    #13 fumagally, Dec 4, 2009
    Last edited: Dec 4, 2009
  13. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    ??

    anyone.... help please...
     
  14. cyon

    cyon Member

    Joined:
    Jan 15, 2003
    Messages:
    322
    Likes Received:
    0
    Trophy Points:
    16
  15. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    error

    hi friend,

    I tested the api that you posted.

    but is showing an error when trying to change the password, stating that the current password is invalid, even if the password being correct this same message appears:

    Fatal error: Uncaught exception 'Exception' with message 'Login Attempt Failed' in /home/uaisys/public_html/xmlapi.php:620 Stack trace: #0 /home/uaisys/public_html/xmlapi.php(768): xmlapi->xmlapi_query('cpanel', Array) #1 /home/uaisys/public_html/alterar.php(15): xmlapi->api1_query('teste', 'Email', 'passwdpop', Array) #2 {main} thrown in /home/uaisys/public_html/xmlapi.php on line 620
     
  16. cyon

    cyon Member

    Joined:
    Jan 15, 2003
    Messages:
    322
    Likes Received:
    0
    Trophy Points:
    16
    Hello

    There was an error in the script. Now the libary is updated. Please download the new file. If the login fails, the script throws an error. For that you can add an try/catch block around your password change call.

    PHP: Exceptions - Manual
     
  17. fumagally

    fumagally New Member

    Joined:
    Nov 25, 2009
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    WOWWWWWW... THANKS VERY MUCH MEN............!!!!!!!!!!

    Works!!!!

    It took only a simple modification as below:


    PHP:
    if ($response === false)
                    {
                        
    error_log("Login Attempt Failed");
                        
    //throw new Exception('Login Attempt Failed');
                        
    echo "Old password is invalid!";
                    }
                    else {
                        echo 
    "Password changed!!!";
                    }
     
  18. Aero7

    Aero7 New Member

    Joined:
    Mar 19, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Thanks for this script guys. Works perfect. Just wanted to know if there is a way for my users to signup and create their own emails instead of me going through cpanel everytime ?


    Thanks :)
     
  19. MattDees

    MattDees Member
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    412
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Houston, TX
    Absolutely:

    PHP:
    include("xmlapi.php");

    $ip "127.0.0.1";
    $root_pass "somepass";

    $account "someuser";

    $email_account "randomemail";
    $email_domain "somedomain.com";
    $email_password "s0m3!!p4$$";
    $email_quota "100"# 100 mB

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);

    $xmlapi->set_debug(1);
    print 
    $xmlapi->api2_query($account"Email""addpop", array(domain=>$email_domainemail => $email_accountpassword => $email_passwordquota => $email_quota ) );
     

Share This Page