Skip to main content

Reset a Password

The following code sample illustrates how to reset a native user's password.


Code Sample

See the C++ environment settings for details on setting the project environment.


<cpp_admin_others_resetpassword.cpp>
/*****************************************************************************************
*
* cpp_admin_others_resetpassword.cpp
*
*
******************************************************************************************/

#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin.h"

using namespace ERUCES;
using namespace std;

int main()
{
string strServer = "localhost";
long nPort = 8888;
string strUser = "ls"; // this is a normal TE user, not necessarily a TE admin user.
string strPswd = "password";
string strNewPswd = "newpassword";

try
{
// Connect to server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
conn->open(strServer, nPort, strUser, strPswd);
cout << "Connected to " << strServer << " as " << strUser << endl << endl;

TEAdmin admin;
admin.attachConnection(conn.operator->());

admin.resetPassword(strUser, strNewPswd); // reset password.

cout << "Password was reset." << endl;

admin.detachConnection();

// Disconnect from server
conn->close();
cout << endl << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}
Output
Connected to localhost as ls

Password was reset.

Disconnected from localhost