- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的 android 应用程序中通过 soap web 服务使用 MySQL 连接开发了一个登录表单(用户名、密码和提交按钮)。在这里我想添加一个“记住密码字段”。我在 Activity 的 XML 资源中编写了这段代码:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/tf_userName"
android:layout_width="194dp"
android:layout_height="wrap_content"
android:layout_x="106dp"
android:layout_y="80dp" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="23dp"
android:layout_y="93dp"
android:text="User name" />
<EditText
android:id="@+id/tf_password"
android:layout_width="189dp"
android:layout_height="wrap_content"
android:layout_x="108dp"
android:layout_y="161dp"
android:inputType="textPassword" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="23dp"
android:layout_y="176dp"
android:text="Password" />
<CheckBox android:layout_below="@+id/passwordview"
android:layout_width="wrap_content" android:text="Remember Password!"
android:layout_height="wrap_content" android:id="@+id/rempasswordcheckbox"
android:layout_x="23dp"
android:layout_y="200dp" />
<Button
android:id="@+id/btn_login"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="273dp"
android:text="Login" />
<TextView
android:id="@+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="350dp"
android:text="Forget My password ?: Click here" />
<Button
android:id="@+id/btn_reg"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="273dp"
android:text="Register" />
<Button
android:id="@+id/btn_logout"
android:layout_width="106dp"
android:layout_height="wrap_content"
android:layout_x="215dp"
android:layout_y="25dp"
android:text="Logout" />
<TextView
android:id="@+id/tv_status"
android:layout_width="151dp"
android:layout_height="38dp"
android:layout_x="26dp"
android:layout_y="234dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
我的 Login.java 文件是:
package com.truebranches;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends Activity {
private final String NAMESPACE = "http://ws.userlogin.com";
private final String URL = "http://192.168.1.168:8085/Login/services/Login?wsdl";
private final String SOAP_ACTION = "http://ws.userlogin.com/authentication";
private final String METHOD_NAME = "authentication";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Button register = (Button) findViewById(R.id.btn_reg);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), Register.class);
startActivity(i);
}
});
Button logout = (Button) findViewById(R.id.btn_logout);
logout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), Login.class);
startActivity(i);
}
});
TextView forgetpassword = (TextView) findViewById(R.id.TextView03);
forgetpassword.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), ForgetPassword.class);
startActivity(i);
}
});
Button login = (Button) findViewById(R.id.btn_login);
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
loginAction();
}
});
}
private void loginAction(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
EditText userName = (EditText) findViewById(R.id.tf_userName);
String user_Name = userName.getText().toString();
EditText userPassword = (EditText) findViewById(R.id.tf_password);
String user_Password = userPassword.getText().toString();
//Pass value for userName variable of the web service
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("userName");//Define the variable name in the web service method
unameProp.setValue(user_Name);//set value for userName variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable
//Pass value for Password variable of the web service
PropertyInfo passwordProp =new PropertyInfo();
passwordProp.setName("password");
passwordProp.setValue(user_Password);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
String status = response.toString();
TextView result = (TextView) findViewById(R.id.tv_status);
result.setText(response.toString());
if(status.equals("Success!"))
{
Intent intent = new Intent(Login.this,HomePage.class);
intent.putExtra("username",userName.getText().toString());
startActivity(intent);
}
else
{
Intent i = new Intent(getApplicationContext(), Login.class);
startActivity(i);
}
}
catch(Exception e){
}
}
}
但是我该如何创建 Java 代码呢?我似乎无法做到这一点。请指导我。
最佳答案
编辑----------------
import....
import android.widget.CheckBox; // <--- Add
import android.content.SharedPreferences; // <--- Add
import android.widget.EditText; // <--- Add
.
.
.
.
private static final String SPF_NAME = "vidslogin"; // <--- Add this
private static final String USERNAME = "username"; // <--- To save username
private static final String PASSWORD = "password"; // <--- To save password
CheckBox chkRememberMe; // <--- You even not taken CheckBox, SILLY WORKER
EditText etUserName, etPassword; // <--- You even not taken CheckBox, SILLY WORKER
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
chkRememberMe = (CheckBox) findViewById(R.id.rempasswordcheckbox); // <--- Instantiate CheckBox...
etUserName = (EditText) findViewById(R.id.tf_userName); // <--- Instantiate EditText...
etPassword = (EditText) findViewById(R.id.tf_password); // <--- Instantiate EditText...
// ADD THIS TO READ SAVED username & password NEXT-TIME OPENING Application
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME,
Context.MODE_PRIVATE);
etUserName.setText(loginPreferences.getString(USERNAME, ""));
etPassword.setText(loginPreferences.getString(PASSWORD, ""));
.
.
.
.
.
.
private void loginAction() {
.
.
.
.
if (status.equals("Success!"))
{
// ADD to save and read next time
String strUserName = etUserName.getText().toString().trim();
String strPassword = etPassword.getText().toString().trim();
if (null == strUserName || strUserName.length() == 0)
{
// showToast("Enter Your Name");
etUserName.requestFocus();
} else if (null == strPassword || strPassword.length() == 0)
{
// showToast("Enter Your Password");
etPassword.requestFocus();
} else
{
if (chkRememberMe.isChecked())
{
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
loginPreferences.edit().putString(USERNAME, strUserName).putString(PASSWORD, strPassword).commit();
} else
{
SharedPreferences loginPreferences = getSharedPreferences(SPF_NAME, Context.MODE_PRIVATE);
loginPreferences.edit().clear().commit();
}
// OVER
Intent intent = new Intent(Login.this, HomePage.class);
intent.putExtra("username", userName.getText().toString());
startActivity(intent);
}
如果 YourCheckBox 发现 isChecked()==true
在登录按钮 onClick 时
只需将用户名和密码保存到SharedPreference。
Declare PREFRENCES_NAME = "Name You Like"
Save Data:-
SharedPreferences settings = getSharedPreferences(PREFRENCES_NAME, 0);
settings.edit().putString("name", strName).putString("pwd", strPass).commit();
Retrieve Data:-
SharedPreferences settings = getSharedPreferences(PREFRENCES_NAME, 0);
String name = settings.getString("name", "");
String password = settings.getString("pwd", "");
Clear Data:-
SharedPreferences settings = getSharedPreferences(
PREFRENCES_NAME, Context.MODE_PRIVATE);
settings.edit().clear().commit();
关于android - 在 Android 应用程序中记住密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11537999/
Internal Server Error: /admin/account/customuser/add/ Traceback (most recent call last): File "C:\
有问题!虽然我发现几乎相似的线程但没有帮助:( 我编写了一个 php 脚本来从我的 MySQL 数据库中获取注册用户的数量。该脚本在我的本地主机上运行良好;它使用给定的用户名、密码和主机名,分别是“r
我正在做一项基于密码的作业,我将 key 和消息放在单独的数组中。我想创建第三个数组,其中包含围绕消息大小的 key ,如下所示: message keykeyk 我已经在这个问题上苦苦挣扎了一段时间
我的几个客户要求我实现图形密码检查器,例如 关于如何实现这种 UI 有什么想法吗? 最佳答案 试着看看这个:https://code.google.com/p/android-lockpattern/
我正在使用 MAMP,每次登录 phpMyAdmin 时,都会收到以下错误/警告消息: the configuration file now needs a secret passphrase (bl
我正在尝试通过将 Visual Studio 2013 连接到我的测试机来调试 WDF 驱动程序。它创建一个名为 WDKRemoteUser 的用户,并在进行测试时尝试自动登录。有人知道这个用户的密码
使用具有指定用户名和密码的 SVN 提交。我希望服务器抛出错误;所以我可以告诉我的用户他/她的密码错误。 相反,在使用错误密码提交后: svn commit "test_file.txt" --use
我正在尝试实现 friend 推荐。 它从节点“你”开始。而且,我想找到节点“安娜”。 换句话说,这是我的两个或更多 friend 共同认识的人。上面的示例节点是 Anna。 如果您的帮助,我将不胜感
我都尝试过 wget --user=myuser --password=mypassword myfile 和 wget --ftp-user=myuser --ftp-password=mypass
我的一位用户提示说,每当他尝试使用默认管理界面(Django 的管理员)添加新用户(auth.User)时,新用户名和密码都会自动填充他自己的。 问题是他在登录时要求 Firefox 记住他的用户名/
我们正在开发一款应用(当然)用于应用购买 (IAP)。我已完成指南中的所有操作以启用 iap,并且一切正常,直到我想要购买为止。 部分代码: MainViewController.m -(vo
我试图创建两个可选匹配项的并集(如下所示),但我得到的不是并集,而是两者的交集。我应该如何更改此查询以获得所需的联合? optional match (a:PA)-[r2:network*2]-(b:
我想将Ansible用作另一个Python软件的一部分。在该软件中,我有一个包含其用户名/密码的主机列表。 有没有一种方法可以将SSH连接的用户/密码传递给Ansible ad-hoc命令或以加密方式
嗨,我在使用xampp的Apache Web服务器上收到错误500。直到我使用.htaccess,.htpasswd文件,错误才出现。我搜索了,但找不到语法错误。我只有1张图片和要保护的索引文件。以下
我一直使用它来编辑用户帐户信息: $this->validate($request, [ 'password' => 'min:6', 'password_confirmation'
我需要使用InstallUtil来安装C# Windows服务。我需要设置服务登录凭据(用户名和密码)。这一切都需要默默地完成。 有没有办法做这样的事情: installutil.exe myserv
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
如果我有一个随机的、16 个字符长的字母数字盐(不同大小写),它是为每个用户生成和存储的,我是否还需要一个站点范围的盐? 换句话说,这样好吗? sha1($user_salt . $password)
我正在开发一个空白程序,该程序将允许用户创建一个帐户,以便他们可以存储其余额和提款/存款。用户输入用户名和密码后,如何存储这些信息以便用户可以登录并查看其余额?我不一定要尝试使其非常安全,我只是希望能
我正在尝试寻找一种通用方法来搜索没有链接到另一个节点或节点集的节点或节点集。例如,我能够找到特定类型(例如 :Style)的所有节点,这些节点以某种方式连接到一组特定的节点(例如 :MetadataR
我是一名优秀的程序员,十分优秀!