【发布时间】:2017-05-27 03:27:36
【问题描述】:
所以我正在使用 aws cognito,我对如何获取密码有点困惑?
如果用户在编辑文本中输入密码,我如何获取用户在注册时输入的密码,以便我可以将他们登录时使用的密码与注册时使用的密码进行比较?
这是我注册用户的代码:
userPool.signUpInBackground(username_ET.getText().toString(), password_ET.getText().toString(), userAttributes, null, signupCallback);
这是我用来登录的代码:
private AuthenticationHandler authenticationHandler = new AuthenticationHandler()
{
@Override
public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice)
{
Log.d(COGNITO_LOGIN,"Login success I think?!");
cognitoUser.getDetailsInBackground(getDetailsHandler);
//Here i need to compare passwords before i can move on.
}
@Override
public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId)
{
Log.d(COGNITO_LOGIN,passwordET.getText().toString());
// The API needs user sign-in credentials to continue
AuthenticationDetails authenticationDetails = new AuthenticationDetails(userId, passwordET.getText().toString(), null);
// Pass the user sign-in credentials to the continuation
authenticationContinuation.setAuthenticationDetails(authenticationDetails);
// Allow the sign-in to continue
authenticationContinuation.continueTask();
}
@Override
public void getMFACode(MultiFactorAuthenticationContinuation multiFactorAuthenticationContinuation) {
// Multi-factor authentication is required; get the verification code from user
multiFactorAuthenticationContinuation.setMfaCode("verificationCode");
// Allow the sign-in process to continue
multiFactorAuthenticationContinuation.continueTask();
}
@Override
public void authenticationChallenge(ChallengeContinuation continuation) {
}
@Override
public void onFailure(Exception exception)
{
// Sign-in failed, check exception for the cause
Log.d(COGNITO_LOGIN,"Login failed!");
Log.d(COGNITO_LOGIN,exception.getMessage());
exceptionMessage(exception.getMessage());
}
};
cognitoUser.getSessionInBackground(authenticationHandler);
使用身份验证处理程序,我只需要传入正确的用户名(或用户 ID)即可使 onSuccess 运行。甚至不需要密码。所以我很困惑,用户必须输入正确的密码才能登录。
【问题讨论】:
-
我不确定我是否理解。您在刚刚发布的代码中提供密码。当您创建 AuthenticationDetails 并将它们添加到延续时。那么你的问题到底是什么?
-
@doorstuck 是的,我提供了密码,但
getgetAuthenticationDetails中的日志语句没有运行。当我输入错误的密码时,它仍然会登录 -
尝试调用注销或重新安装应用程序。然后它没有存储凭据,它将使用
getAuthenticationDetails方法询问密码。
标签: android amazon-web-services aws-lambda aws-sdk aws-cognito