Example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt

List of usage examples for org.springframework.security.crypto.bcrypt BCrypt gensalt

Introduction

In this page you can find the example usage for org.springframework.security.crypto.bcrypt BCrypt gensalt.

Prototype

public static String gensalt() 

Source Link

Document

Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable default for the number of hashing rounds to apply

Usage

From source file:com.tsg.techsupportmvc.dao.UserCreate.java

public static void main(String[] args) {

    String password = "1234";
    String salt = BCrypt.gensalt();
    String hash = BCrypt.hashpw(password, salt);

    System.out.println(salt);/*from  w  w w.j  av  a  2 s  .  c o  m*/
    System.out.println(hash);
}

From source file:de.ingrid.iplug.PlugServer.java

/**
 * To start the plug server from the commandline.
 * @param args Arguments for the plug server e.g. --descriptor .
 * @throws Exception If something goes wrong.
 *///from  w ww .  ja v a 2 s  .com
public static void main(String[] args) throws Exception {
    Map arguments = readParameters(args);
    PlugDescription plugDescription = null;
    File plugDescriptionFile = new File(PLUG_DESCRIPTION);
    if (arguments.containsKey("--plugdescription")) {
        plugDescriptionFile = new File((String) arguments.get("--plugdescription"));
    }
    plugDescription = loadPlugDescriptionFromFile(plugDescriptionFile);

    PlugServer server = null;
    if (arguments.containsKey("--resetPassword")) {
        String pw = (String) arguments.get("--resetPassword");
        fLogger.info("Resetting password to '" + pw + "' ...");
        plugDescription.setIplugAdminPassword(BCrypt.hashpw(pw, BCrypt.gensalt()));
        XMLSerializer serializer = new XMLSerializer();
        serializer.serialize(plugDescription, plugDescriptionFile);
        fLogger.info("Done ... please restart iPlug.");
        return;
    } else if (arguments.containsKey("--migratePassword")) {
        fLogger.info("Migrating plain text password from PlugDescription to encrypted one ...");
        plugDescription.setIplugAdminPassword(
                BCrypt.hashpw(plugDescription.getIplugAdminPassword(), BCrypt.gensalt()));
        XMLSerializer serializer = new XMLSerializer();
        serializer.serialize(plugDescription, plugDescriptionFile);
        fLogger.info("Done ... please restart iPlug.");
        return;
    } else if (arguments.containsKey("--descriptor")) {
        File commConf = new File((String) arguments.get("--descriptor"));
        server = new PlugServer(plugDescription, commConf, plugDescriptionFile, 60 * 1000);
    }
    if (server != null) {
        server.initPlugServer();
    }
}

From source file:de.ingrid.interfaces.csw.admin.command.AdminManager.java

/**
 * Read the override configuration and convert the clear text password to a bcrypt-hash,
 * which is used and needed by the base-webapp v3.6.1 
 *//* w w  w  .  j  ava  2 s.  c o  m*/
private static void migratePassword() {
    try {
        InputStream is = new FileInputStream("conf/config.properties");
        Properties props = new Properties();
        props.load(is);
        String oldPassword = props.getProperty("ingrid.admin.password");
        is.close();

        props.setProperty("ingrid.admin.password", BCrypt.hashpw(oldPassword, BCrypt.gensalt()));

        OutputStream os = new FileOutputStream("conf/config.override.properties");
        props.store(os, "Override configuration written by the application");
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.radixware.manager.hibernateDAO.Config.UserEntity.java

public void setPwd(String pwd) {
    this.pwd = BCrypt.hashpw(pwd, BCrypt.gensalt());
}

From source file:com.tsg.techsupportmvc.dao.UserDaoDbImpl.java

@Override
public String getSalt() {

    return BCrypt.gensalt();

}

From source file:de.appsolve.padelcampus.utils.LoginUtil.java

public void updateLoginCookie(HttpServletRequest request, HttpServletResponse response) {
    Player player = sessionUtil.getUser(request);
    if (player != null) {
        UUID cookieUUID = UUID.randomUUID();
        UUID cookieValue = UUID.randomUUID();
        String cookieValueHash = BCrypt.hashpw(cookieValue.toString(), BCrypt.gensalt());
        LoginCookie loginCookie = new LoginCookie();
        loginCookie.setUUID(cookieUUID.toString());
        loginCookie.setPlayerUUID(player.getUUID());
        loginCookie.setLoginCookieHash(cookieValueHash);
        loginCookie.setValidUntil(new LocalDate().plusYears(1));
        loginCookieDAO.saveOrUpdate(loginCookie);
        Cookie cookie = new Cookie(COOKIE_LOGIN_TOKEN, cookieUUID.toString() + ":" + cookieValue.toString());
        cookie.setDomain(request.getServerName());
        cookie.setMaxAge(ONE_YEAR_SECONDS);
        cookie.setPath("/");
        response.addCookie(cookie);//  ww w.  jav a 2 s  .  c o m
    }
}

From source file:de.ingrid.interfaces.csw.admin.command.AdminManager.java

/**
 * Read the override configuration and write a new bcrypt-hash password.
 *///w ww  . jav  a2  s .  com
private static void resetPassword(String newPassword) {
    try {
        InputStream is = new FileInputStream("conf/config.override.properties");
        Properties props = new Properties();
        props.load(is);
        props.setProperty("ingrid.admin.password", BCrypt.hashpw(newPassword, BCrypt.gensalt()));

        OutputStream os = new FileOutputStream("conf/config.override.properties");
        props.store(os, "Override configuration written by the application");
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cfitzarl.cfjwed.data.model.Account.java

public void setPassword(String clearText) {
    password = BCrypt.hashpw(clearText, BCrypt.gensalt());
}

From source file:org.biokoframework.system.services.crypto.impl.ProdEntityEncryptionService.java

private String encryptField(String plainValue, String encryptionType) {
    if (ONE_WAY_HINT.equals(encryptionType)) {
        String salt = BCrypt.gensalt();
        String encryptedValue = BCrypt.hashpw(plainValue, salt);
        return encryptedValue;
    } else if (TWO_WAY_HINT.equals(encryptionType)) {
        try {//  w  w  w .  j ava 2 s  . co  m
            return Base64.encodeBase64String(plainValue.getBytes(CHARSET));
        } catch (UnsupportedEncodingException exception) {
            System.out.println("[easy-men] problem with the encoding " + CHARSET);
            return null;
        }
        //         //   AES encryption, requires Java7
        //         String salt = KeyGenerators.string().generateKey();
        //         TextEncryptor textEncryptor = Encryptors.queryableText(_password, salt);
        //         return new StringBuilder(textEncryptor.encrypt(plainValue)).append(":").append(salt).toString();
    }
    return null;
}

From source file:bean.RedSocial.java

/**
 * //from w  ww.  j  a  va 2 s  . c o  m
 * @param _username
 * @param _email
 * @param _password 
 */
@Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = transactionalBusinessException.ComentariosViaException.class)
public void solicitarAcceso(String _username, String _email, String _password) {
    if (daoUsuario.obtenerUsuario(_username) != null) {
        throw new exceptionsBusiness.UsernameNoDisponible();
    }

    String hash = BCrypt.hashpw(_password, BCrypt.gensalt());

    Token token = new Token(_username, _email, hash);
    daoToken.guardarToken(token);

    //enviar token de acceso a la direccion email

    String correoEnvia = "skala2climbing@gmail.com";
    String claveCorreo = "vNspLa5H";

    // La configuracin para enviar correo
    Properties properties = new Properties();
    properties.put("mail.smtp.host", "smtp.gmail.com");
    properties.put("mail.smtp.starttls.enable", "true");
    properties.put("mail.smtp.port", "587");
    properties.put("mail.smtp.auth", "true");
    properties.put("mail.user", correoEnvia);
    properties.put("mail.password", claveCorreo);

    // Obtener la sesion
    Session session = Session.getInstance(properties, null);

    try {
        // Crear el cuerpo del mensaje
        MimeMessage mimeMessage = new MimeMessage(session);

        // Agregar quien enva el correo
        mimeMessage.setFrom(new InternetAddress(correoEnvia, "Skala2Climbing"));

        // Los destinatarios
        InternetAddress[] internetAddresses = { new InternetAddress(token.getEmail()) };

        // Agregar los destinatarios al mensaje
        mimeMessage.setRecipients(Message.RecipientType.TO, internetAddresses);

        // Agregar el asunto al correo
        mimeMessage.setSubject("Confirmacin de registro");

        // Creo la parte del mensaje
        MimeBodyPart mimeBodyPart = new MimeBodyPart();
        String ip = "90.165.24.228";
        mimeBodyPart.setText("Confirme su registro pulsando en el siguiente enlace: http://" + ip
                + ":8383/redsocialcolaborativaclientangularjs/confirmacion.html?" + "token="
                + token.getToken());
        //mimeBodyPart.setText("Confirme su registro pulsando en el siguiente enlace: "+"Enlace an no disponible");

        // Crear el multipart para agregar la parte del mensaje anterior
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(mimeBodyPart);

        // Agregar el multipart al cuerpo del mensaje
        mimeMessage.setContent(multipart);

        // Enviar el mensaje
        Transport transport = session.getTransport("smtp");
        transport.connect(correoEnvia, claveCorreo);
        transport.sendMessage(mimeMessage, mimeMessage.getAllRecipients());
        transport.close();

    } catch (UnsupportedEncodingException | MessagingException ex) {
        throw new ErrorEnvioEmail();
    }

}