首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从aws认知- android中获取密码?

如何从aws认知- android中获取密码?
EN

Stack Overflow用户
提问于 2017-01-12 06:03:21
回答 1查看 5.3K关注 0票数 1

所以,我使用aws的认知,我有点困惑如何获得密码?

如果用户在编辑文本中输入密码,我如何获得用户在注册时输入的密码,以便将他们登录的密码与注册的密码进行比较?

下面是我注册用户的代码:

代码语言:javascript
复制
userPool.signUpInBackground(username_ET.getText().toString(), password_ET.getText().toString(), userAttributes, null, signupCallback);

下面是我用来登录的代码:

代码语言:javascript
复制
 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);

使用身份验证处理程序,我只需传入正确的用户名(或userID)即可运行onSuccess。甚至不需要密码。所以我很困惑,到哪里用户也必须输入正确的密码才能让他们登录。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-13 00:07:17

你不需要比较密码。当你注册时,科尼托会为你注册的密码存储一个盐和一个验证器。科尼图不会以你输入的形式存储你的密码,而只是一个盐和验证器。当您使用下面的代码时,Cognito使用安全远程密码协议来匹配内部存储的验证器。由于我们使用您为计算提供的密码,所以无法检索它。注意,在onSuccess回调中,如果调用成功,您将得到令牌,如下所示。

代码语言:javascript
复制
// Callback handler for the sign-in process 
AuthenticationHandler authenticationHandler = new AuthenticationHandler() { 

    @Override 
    public void onSuccess(CognitoUserSession cognitoUserSession) { 
        // Sign-in was successful, cognitoUserSession will contain tokens for the user   
    }

    @Override
    public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) { 
        // The API needs user sign-in credentials to continue
        AuthenticationDetails authenticationDetails = new AuthenticationDetails(userId, password, 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(mfaVerificationCode);
        // Allow the sign-in process to continue
        multiFactorAuthenticationContinuation.continueTask();
    }

    @Override
    public void onFailure(Exception exception) {
        // Sign-in failed, check exception for the cause
    } 
};

// Sign-in the user 
cognitoUser.getSessionInBackground(authenticationHandler);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41606127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档