本文整理汇总了Java中org.jivesoftware.smack.packet.Registration.setPassword方法的典型用法代码示例。如果您正苦于以下问题:Java Registration.setPassword方法的具体用法?Java Registration.setPassword怎么用?Java Registration.setPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.packet.Registration
的用法示例。
在下文中一共展示了Registration.setPassword方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changePassword
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
* Changes the password of the currently logged-in account. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support changing passwords; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws XMPPException if an error occurs when changing the password.
*/
public void changePassword(String newPassword) throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
reg.setUsername(StringUtils.parseName(connection.getUser()));
reg.setPassword(newPassword);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例2: changePassword
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
* Changes the password of the currently logged-in account. This operation can only
* be performed after a successful login operation has been completed. Not all servers
* support changing passwords; an XMPPException will be thrown when that is the case.
*
* @throws IllegalStateException if not currently logged-in to the server.
* @throws org.jivesoftware.smack.XMPPException if an error occurs when changing the password.
*/
public void changePassword(String newPassword) throws XMPPException {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
reg.setUsername(StringUtils.parseName(connection.getUser()));
reg.setPassword(newPassword);
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例3: regist
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
* 注册用户
* @param xmppConnection
* @param userName
* @param password
* @return 1、注册成功 0、服务器没有返回结果2、这个账号已经存在3、注册失败
*/
public static int regist(XMPPConnection xmppConnection, String userName, String password) {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(xmppConnection.getServiceName());
registration.setUsername(userName);
registration.setPassword(password);
// 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!
registration.addAttribute("android", "fhr");
PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = xmppConnection.createPacketCollector(filter);
xmppConnection.sendPacket(registration);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止请求results(是否成功的结果)
collector.cancel();
if (result == null) {
Log.e("regist", "No response from server.");
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
Log.v("regist", "regist success.");
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 2;
} else {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 3;
}
}
}
示例4: register
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
* 注册
*
* @param account
* 注册帐号
* @param password
* 注册密码
* @return 1、注册成功 0、服务器没有返回结果2、这个账号已经存在3、注册失败
*/
public static int register(XMPPConnection mXMPPConnection,String account, String password) {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(mXMPPConnection.getServiceName());
// 注意这里createAccount注册时,参数是UserName,不是jid,是"@"前面的部分。
reg.setUsername(account);
reg.setPassword(password);
// 这边addAttribute不能为空,否则出错。所以做个标志是android手机创建的吧!!!!!
reg.addAttribute("android", "geolo_createUser_android");
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector =mXMPPConnection.createPacketCollector(filter);
mXMPPConnection.sendPacket(reg);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止请求results(是否成功的结果)
collector.cancel();
if (result == null) {
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
return 2;
} else {
return 3;
}
}
}
示例5: createAccount
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
* Creates a new account using the specified username, password and account attributes.
* The attributes Map must contain only String name/value pairs and must also have values
* for all required attributes.
*
* @param username the username.
* @param password the password.
* @param attributes the account attributes.
* @throws XMPPException if an error occurs creating the account.
* @see #getAccountAttributes()
*/
public void createAccount(String username, String password, Map<String, String> attributes)
throws XMPPException
{
if (!supportsAccountCreation()) {
throw new XMPPException("Server does not support account creation.");
}
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
reg.setUsername(username);
reg.setPassword(password);
for(String s : attributes.keySet()){
reg.addAttribute(s, attributes.get(s));
}
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例6: createAccount
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
/**
* Creates a new account using the specified username, password and account attributes.
* The attributes Map must contain only String name/value pairs and must also have values
* for all required attributes.
*
* @param username the username.
* @param password the password.
* @param attributes the account attributes.
* @throws org.jivesoftware.smack.XMPPException if an error occurs creating the account.
* @see #getAccountAttributes()
*/
public void createAccount(String username, String password, Map<String, String> attributes)
throws XMPPException
{
if (!supportsAccountCreation()) {
throw new XMPPException("Server does not support account creation.");
}
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(connection.getServiceName());
reg.setUsername(username);
reg.setPassword(password);
for(String s : attributes.keySet()){
reg.addAttribute(s, attributes.get(s));
}
PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()),
new PacketTypeFilter(IQ.class));
PacketCollector collector = connection.createPacketCollector(filter);
connection.sendPacket(reg);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (result == null) {
throw new XMPPException("No response from server.");
}
else if (result.getType() == IQ.Type.ERROR) {
throw new XMPPException(result.getError());
}
}
示例7: execute
import org.jivesoftware.smack.packet.Registration; //导入方法依赖的package包/类
@Override
public XmppResult execute() {
// TODO Auto-generated method stub
XmppResult result = createResult();
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(XmppConnectionUtils.getXmppHost());
reg.setUsername(mUserName);
reg.setPassword(mPasswd);
PacketFilter filter = new AndFilter(new PacketIDFilter(
reg.getPacketID()), new PacketTypeFilter(IQ.class));
IQ iq = null;
try {
XMPPConnection connection = XmppConnectionUtils.getInstance()
.getConnection();
if (connection.isAuthenticated()) {
XmppConnectionUtils.getInstance().closeConnection();
connection = XmppConnectionUtils.getInstance().getConnection();
}
PacketCollector collector = XmppConnectionUtils.getInstance()
.getConnection().createPacketCollector(filter);
XmppConnectionUtils.getInstance().getConnection().sendPacket(reg);
iq = (IQ) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
collector.cancel();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
result.obj = e.getMessage();
return result;
}
if (iq == null) {
result.obj = "No response from server.";
} else if (iq.getType() == IQ.Type.RESULT) {
result.status = Status.SUCCESS;
} else {
result.obj = "unknown error";
}
return result;
}