2014-09-15 2 views
0

내 응용 프로그램 내 봄 보안을 사용하여 내 데이터베이스 .the 암호는 암호로 암호화 된 form.so 로그인시 비밀 번호를 보내는 암호화 된 양식으로 변환해야합니다 그럼 내가 보내는 비밀 번호와 데이터베이스에 존재하는 비밀 번호를 비교할 수 있어야합니다. 일치하는 경우, 성공적인 로그인이 발생해야합니다. 이 내 스프링 security.xml암호 보안과 봄 보안에서 사용자를 인증하는 방법

여기
<authentication-manager"> 
     <authentication-provider > 
      <password-encoder ref="encoder"/> 
       <jdbc-user-service data-source-ref="dataSource" 
        users-by-username-query="select email,password from user where email=?" 
        /> 
      </authentication-provider> 
</authentication-manager> 
<beans:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/> 

와 이메일, 비밀번호, contactno, 주소를 포함 내 사용자 테이블입니다. 도움이되는 방법 사용자가 입력하는 비밀번호와 matech 여부를 확인하는 방법에 대해 암호화 된 비밀번호 값을 어떻게 확인할 수 있습니까?

답변

0

사용자는 자신 만의 PasswordEncoder를 작성하여 사용자를 봄용으로 안전하게 전송할 수 있습니다.

@Component("PasswordEncoder") 
public class PasswordEncoderimpl implements PasswordEncoder{ 
    @Override 
    public String encodePassword(String rawPass, Object salt) { 
     //it is the algorithm the transfer password to encrypted password 
    } 
    @Override 
    public boolean isPasswordValid(String encPass, String rawPass, Object salt) { 
     //encPass is the password in your database 
     //rawPass is the password user entering 
     //then you can write it like 
     return encPass.euqals(encodePassword(rawPass)); 
    } 
} 

는 그런 다음 스프링 security.xml는 다음과 같습니다

<authentication-manager> 
    <authentication-provider> 
     <password-encoder ref="PasswordEncoder"> 
     </password-encoder> 
    </authentication-provider> 
</authentication-manager> 
관련 문제