當前位置: 首頁>>代碼示例>>Java>>正文


Java StandardPasswordEncoder類代碼示例

本文整理匯總了Java中org.springframework.security.crypto.password.StandardPasswordEncoder的典型用法代碼示例。如果您正苦於以下問題:Java StandardPasswordEncoder類的具體用法?Java StandardPasswordEncoder怎麽用?Java StandardPasswordEncoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StandardPasswordEncoder類屬於org.springframework.security.crypto.password包,在下文中一共展示了StandardPasswordEncoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testBcrypt

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Test
public void testBcrypt(){
	String pwd = "jfish";
	StandardPasswordEncoder def = new StandardPasswordEncoder();
	BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
	
	TimeCounter time = new TimeCounter("sha");
	int times = 1;
	time.start();
	LangOps.ntimesRun(times, ()->{
		def.encode(pwd);
	});
	time.stop();
	
	time.restart("bcrypt");
	LangOps.ntimesRun(times, ()->{
		String str = encoder.encode(pwd);
		System.out.println("BCrypt "+str.length()+":"+str);
	});
	time.stop();
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:22,代碼來源:PasswordEncoderTest.java

示例2: registera

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@RequestMapping(value="/register", method = RequestMethod.POST)
	public String registera(Locale locale, 
			@RequestParam(value="username", required=false) String username,
			@RequestParam(value="password", required=false) String password,
			@RequestParam(value="firstName", required=false) String firstName,
			@RequestParam(value="lastName", required=false) String lastName,
			@RequestParam(value="email", required=false) String email,
			Model model) {	
		StandardPasswordEncoder encoder = new StandardPasswordEncoder();
		User user = new User();
		user.setUsername(username);
		user.setPassword(encoder.encode(password));
		user.setFirstName(firstName);
		user.setLastName(lastName);
		user.setEmail(email);
//		user.setStatus(status);
//		List<Roles> roles = new ArrayList<>();
//		user.setRoles(roles);
		usersRepository.save(user);
		return "redirect:login";
	}
 
開發者ID:rgajam,項目名稱:sb-starter,代碼行數:22,代碼來源:RegistrationCtrl.java

示例3: getPasswordEncoder

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
public static PasswordEncoder getPasswordEncoder(String algorithm) {
    if (algorithm == null) {
        algorithm = "";
    }

    switch (algorithm) {
        case BCRYPT_ENCODER:
            return new BCryptPasswordEncoder();
        case NO_ENCODER:
            return NoOpPasswordEncoder.getInstance();
        case SHA_256_ENCODER:
            return new StandardPasswordEncoder();
        default: {
            LOGGER.error("No password encoder for algorithm " + algorithm + " found. "
            + "Password encoding is switched off.");
            return NoOpPasswordEncoder.getInstance();
        }
    }
}
 
開發者ID:patka,項目名稱:cognitor,代碼行數:20,代碼來源:PasswordEncoderFactory.java

示例4: encodePassword

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
/**
 * Encodes a given raw password with random salt via Spring {@link StandardPasswordEncoder}.
 *
 * @param  rawPassword  plaintext password
 *
 * @return  encoded password
 */
public static String encodePassword(String rawPassword) {

    /**
     * TODO: Think about to use a better password encoder
     *
     * Comment within StandardPasswordEncoder:
     *
     * If you are developing a new system,
     * {@link org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder} is
     * a better choice both in terms of security and interoperability with other languages.
     */

    StandardPasswordEncoder encoder = new StandardPasswordEncoder();

    return encoder.encode(rawPassword);
}
 
開發者ID:synyx,項目名稱:urlaubsverwaltung,代碼行數:24,代碼來源:CryptoUtil.java

示例5: testStandardPasswordEncoder

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Test
public void testStandardPasswordEncoder(){
    PasswordEncoder passwordEncoder = new StandardPasswordEncoder("web_qq");
    String password1 = passwordEncoder.encode("12345");
    String password2 = passwordEncoder.encode("mingguobin4");
    System.out.println("password1:"+password1);
    System.out.println("password2:"+password2);
    System.out.println(passwordEncoder.matches("mingguobin4",password1));
}
 
開發者ID:damingerdai,項目名稱:web-qq,代碼行數:10,代碼來源:PasswordEncoderTest.java

示例6: verifyPasswordEncoderByCustomClassName

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Test
public void verifyPasswordEncoderByCustomClassName() {
    final PasswordEncoderProperties p = new PasswordEncoderProperties();
    p.setType(StandardPasswordEncoder.class.getName());
    p.setSecret("SECRET");
    final PasswordEncoder e = Beans.newPasswordEncoder(p);
    assertNotNull(e);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:9,代碼來源:DefaultPasswordEncoderTests.java

示例7: createUserDetails

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
private static UserDetails createUserDetails(String whiteList, SystemUser.Role role) {
    SystemUser systemUser = new SystemUser();
    systemUser.setId(1L);
    systemUser.setUsername("username");
    systemUser.setRole(role);
    systemUser.setPasswordAsPlaintext("password", new StandardPasswordEncoder());
    systemUser.setIpWhiteList(whiteList);

    return new UserInfo.UserInfoBuilder(systemUser).createUserInfo();
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:11,代碼來源:RemoteAddressBlockerTest.java

示例8: testSpringPasswordEncoderInstance

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Test
public void testSpringPasswordEncoderInstance() {
    PasswordEncoder passwordEncoder = autoWiredIdmIdmEngineConfiguration.getPasswordEncoder();

    autoWiredIdmIdmEngineConfiguration.setPasswordEncoder(new SpringEncoder(new Md5PasswordEncoder()));
    validatePassword();

    autoWiredIdmIdmEngineConfiguration.setPasswordEncoder(new SpringEncoder(new StandardPasswordEncoder()));
    validatePassword();
    
    autoWiredIdmIdmEngineConfiguration.setPasswordEncoder(passwordEncoder);
}
 
開發者ID:flowable,項目名稱:flowable-engine,代碼行數:13,代碼來源:SpringPasswordEncoderTest.java

示例9: validate

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Override
public void validate(Object target, Errors errors) {
    PasswordUpdateForm form = (PasswordUpdateForm) target;
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    User user = (User) authentication.getPrincipal();
    if (!new StandardPasswordEncoder().matches(form.getCurrentPassword(), user.getPassword())) {
        errors.rejectValue("currentPassword", "error.wrongPassword");
    }
    if (!form.getNewPassword().equals(form.getNewPasswordConfirm())) {
        errors.rejectValue("newPasswordConfirm", "error.unmatched");
    }
}
 
開發者ID:ksoichiro,項目名稱:todo,代碼行數:13,代碼來源:PasswordMatchValidator.java

示例10: update

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@RequestMapping("/update")
public String update(@AuthenticationPrincipal User user, @Validated PasswordUpdateForm form, BindingResult bindingResult) {
    if (bindingResult.hasErrors()) {
        return edit(form);
    }
    user.setPassword(new StandardPasswordEncoder().encode(form.getNewPassword()));
    userRepository.save(user);
    return "redirect:/";
}
 
開發者ID:ksoichiro,項目名稱:todo,代碼行數:10,代碼來源:PasswordController.java

示例11: createPasswordServiceDbImpl

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
public static PasswordServiceImpl createPasswordServiceDbImpl() {
	PasswordServiceImpl ret = new PasswordServiceImpl();

	ret.setPasswordEncoder(new StandardPasswordEncoder("test"));

	UserService userService = UserServiceImplFactory.createUsersServiceImpl();
	ret.setUserService(userService);

	PasswordDao passwordDao = Mockito.mock(PasswordDao.class);
	ret.setPasswordDao(passwordDao);

	when(passwordDao.findPasswordByUserUuid(UserFactory.EXISTENT_USER))
			.thenReturn(PasswordFactory.createExistentUserPassword());
	when(passwordDao.findPasswordByUserUuid(UserFactory.NON_EXISTENT_USER)).thenReturn(null);
	when(passwordDao.findPasswordByUserUuid(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD)).thenReturn(null);
	when(passwordDao.findPasswordByUserUuid(UserFactory.USER_RESULT_IN_EXCEPTION))
			.thenThrow(new IllegalStateException("Simulate unexpected excception"));
	when(passwordDao.findPasswordByUserUuid(UserFactory.EXISTENT_USER_2_PROBLEM_WITH_PASSWORD))
			.thenThrow(new IllegalStateException("Simulate unexpected excception"));

	when(passwordDao.updateUserPassword(eq(UserFactory.EXISTENT_USER), anyString())).thenReturn(1);
	when(passwordDao.updateUserPassword(eq(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD), anyString()))
			.thenReturn(0);

	when(passwordDao.setRestorationToken(eq(UserFactory.EXISTENT_USER), anyString())).thenReturn(1);
	when(passwordDao.setRestorationToken(eq(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD), anyString()))
			.thenReturn(0);

	return ret;
}
 
開發者ID:skarpushin,項目名稱:summerb,代碼行數:31,代碼來源:PasswordServiceDbImplFactory.java

示例12: initAdminUserIfNotExists

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
private void initAdminUserIfNotExists()
{
	User myuser = userManager.getUserByEmail(config.ADMIN_USER);

	if (myuser == null)
	{
		// first user
		myuser = new User();
		UserGroup myGroup = new UserGroup();
		myuser.setAdmin(true);
		myuser.setFirstname("Admin");
		myuser.setLastname("User");
		myuser.setEmail(config.ADMIN_USER);
		StandardPasswordEncoder sp = new StandardPasswordEncoder();
		myuser.setPassword(sp.encode(config.ADMIN_PASSWORD));
		myuser.setDisabled(false);
		myuser.setUserGroup(myGroup);
		userManager.saveOrUpdateUser(myuser);

		// generate empty project
		ProjectManager projectManager = (ProjectManager) AppContext.getApplicationContext().getBean("ProjectManager", ProjectManager.class);
		projectManager.createProject(myuser, false);

		myGroup.setMaxProjects(50);
		userManager.saveOrUpdateUser(myuser);
	}
}
 
開發者ID:bonprix,項目名稱:solidsearch-bot,代碼行數:28,代碼來源:BotInitializer.java

示例13: encodePassword

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Test
public void encodePassword() throws Exception {
	StandardPasswordEncoder encoder = new StandardPasswordEncoder();
	String result = encoder.encode("password01");
	assertTrue(encoder.matches("password01", result));
	logger.info("Encoded password is {}", result);
	assertThat(result,is(notNullValue()));
}
 
開發者ID:lucamartellucci,項目名稱:bookshop-api,代碼行數:9,代碼來源:PasswordEncoder.java

示例14: onStartup

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@PostConstruct
public void onStartup() {

    List<User> allUsers = userRepository.findAll();

    if (allUsers.size() == 0) {
        userRepository.save(new User("admin", new StandardPasswordEncoder().encode("admin"), "admin"));
    }
}
 
開發者ID:djschilling,項目名稱:workinghours,代碼行數:10,代碼來源:Startup.java

示例15: changePassword

import org.springframework.security.crypto.password.StandardPasswordEncoder; //導入依賴的package包/類
@Override
public void changePassword(String username, String password) {

    User user = userRepository.findOne(username);
    user.setPassword(new StandardPasswordEncoder().encode(password));
    userRepository.save(user);
}
 
開發者ID:djschilling,項目名稱:workinghours,代碼行數:8,代碼來源:UserServiceImpl.java


注:本文中的org.springframework.security.crypto.password.StandardPasswordEncoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。