List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:es.tid.cosmos.platform.injection.server.FrontendPassword.java
@Override public boolean authenticate(String username, String password, ServerSession session) { LOG.debug(String.format("received %s as username, %d chars as password", username, password.length())); boolean ans = false; ResultSet resultSet = null;// www .j a va 2s. c o m PreparedStatement preparedStatement = null; Connection connection = null; try { connection = this.connect(this.frontendDbUrl, this.dbName, this.dbUserName, this.dbPassword); String sql = "SELECT password FROM auth_user WHERE username = ?"; preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, username); resultSet = preparedStatement.executeQuery(); String algorithm = ""; String hash = ""; String salt = ""; while (resultSet.next()) { StringTokenizer algorithmSaltHash = new StringTokenizer(resultSet.getString(1), DJANGO_SEPARATOR); algorithm = algorithmSaltHash.nextToken(); salt = algorithmSaltHash.nextToken(); hash = algorithmSaltHash.nextToken(); } // while if (algorithm.equals("sha1")) { ans = hash.equals(DigestUtils.shaHex(salt + password)); } else if (algorithm.equals("md5")) { ans = hash.equals(DigestUtils.md5Hex(salt + password)); } else { LOG.warn("Unknown algorithm found in DB: " + algorithm); } // if else if } catch (SQLException e) { LOG.error(e.getMessage(), e); return false; } finally { if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { LOG.error("could not close a result set", e); } // try catch } // if if (preparedStatement != null) { try { preparedStatement.close(); } catch (SQLException e) { LOG.error("could not close a database statement", e); } // try catch } // if if (connection != null) { try { connection.close(); } catch (SQLException e) { LOG.error("could not close a database connection", e); } // try catch } // if } // try catch finally return ans; }
From source file:it.marcoberri.mbmeteo.action.chart.Base.java
/** * * @param params/*from ww w .j ava 2s .c o m*/ * @return */ protected String getCacheKey(HashMap<String, String> params) { try { final StringBuilder s = new StringBuilder(); for (String k : params.keySet()) { s.append(k); s.append(params.get(k)); } return DigestUtils.shaHex(s.toString()); } catch (final Exception e) { log.error(e); return null; } }
From source file:com.ideabase.repository.core.service.UserServiceImpl.java
private String buildUserHashKey(final User pUser) { return DigestUtils.shaHex(pUser.getUser() + pUser.getPassword()); }
From source file:edu.psu.citeseerx.myciteseer.web.AppidGenerationController.java
/** * Generates a SHA key using username and e-mail as data * @param username//from w w w . jav a 2 s . com * @param email * @return the genarated key */ private String generateKey(String username, String email) { return DigestUtils.shaHex(username + email); }
From source file:com.gson.oauth.Pay.java
/** * ??//from w w w .ja v a 2 s. c om * @param timestamp * @param noncestr * @param packages * @return * @throws UnsupportedEncodingException */ public static String paySign(String timestamp, String noncestr, String packages) throws UnsupportedEncodingException { Map<String, String> paras = new HashMap<String, String>(); paras.put("appid", ConfKit.get("AppId")); paras.put("timestamp", timestamp); paras.put("noncestr", noncestr); paras.put("package", packages); paras.put("appkey", ConfKit.get("paySignKey")); // appid?timestamp?noncestr?package ? appkey String string1 = createSign(paras, false); String paySign = DigestUtils.shaHex(string1); return paySign; }
From source file:com.enonic.cms.itest.client.InternalClientImpl_changeUserPasswordTest.java
@Test public void change_password() { UserStoreConfig userStoreConfig = new UserStoreConfig(); userStoreConfig.addUserFieldConfig(createUserStoreUserFieldConfig(UserFieldType.FIRST_NAME, "required")); userStoreConfig.addUserFieldConfig(createUserStoreUserFieldConfig(UserFieldType.LAST_NAME, "required")); userStoreConfig.addUserFieldConfig(createUserStoreUserFieldConfig(UserFieldType.INITIALS, "required")); createLocalUserStore("myLocalStore", true, userStoreConfig); fixture.flushAndClearHibernateSession(); UserFields userFields = new UserFields(); userFields.setFirstName("First name"); userFields.setLastName("Last name"); userFields.setInitials("INI"); createNormalUser("testuser", "myLocalStore", userFields); // verify//from w w w.j av a2 s . co m UserEntity resultUser = fixture.findUserByName("testuser"); assertEquals("INI", resultUser.getUserFields().getInitials()); assertEquals(DigestUtils.shaHex("password"), resultUser.getPassword()); loginPortalUser("testuser"); // exercise ChangeUserPasswordParams params = new ChangeUserPasswordParams(); params.userstore = "myLocalStore"; params.username = "testuser"; params.password = "changed"; internalClient.changeUserPassword(params); // verify resultUser = fixture.findUserByName("testuser"); assertEquals(DigestUtils.shaHex("changed"), resultUser.getPassword()); }
From source file:com.leclercb.taskunifier.gui.plugins.PluginLicense.java
private boolean checkValidLicense() { if (this.email == null || this.email.length() == 0) return false; if (this.serial == null || this.serial.length() == 0) return false; String data = this.email + this.cipher; String validSerial = DigestUtils.shaHex(data).toUpperCase(); return EqualsUtils.equals(this.serial, validSerial); }
From source file:com.ebay.pulsar.analytics.metricstore.granularity.GranularityTest.java
private void testDruidGranularity() { String d1 = "7200000"; String origin1 = "1970-01-01T00:07:00Z"; DurationGranularity c1 = new DurationGranularity(d1); DurationGranularity c2 = new DurationGranularity(d1); assertArrayEquals(c1.cacheKey(), c2.cacheKey()); c1 = new DurationGranularity(d1, origin1); c2 = new DurationGranularity(d1, origin1); assertArrayEquals(c1.cacheKey(), c2.cacheKey()); assertEquals(d1, c2.getDuration());/* www . j a va 2 s.c o m*/ assertEquals(origin1, c2.getOrigin()); assertEquals("duration", c2.getType()); c2 = new DurationGranularity(d1); assertTrue(!DigestUtils.shaHex(c1.cacheKey()).equals(DigestUtils.shaHex(c2.cacheKey()))); c2 = new DurationGranularity("7300000", origin1); assertTrue(!DigestUtils.shaHex(c1.cacheKey()).equals(DigestUtils.shaHex(c2.cacheKey()))); c2 = new DurationGranularity("7200000", "1970-01-02T00:07:00Z"); assertTrue(!DigestUtils.shaHex(c1.cacheKey()).equals(DigestUtils.shaHex(c2.cacheKey()))); assertTrue(!c1.equals(null)); c2 = new DurationGranularity(null); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new DurationGranularity(d1); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new DurationGranularity(d1, null); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new DurationGranularity(d1, origin1); assertTrue(c1.equals(c2)); assertTrue(c2.equals(c1)); assertTrue(c1.equals(c1)); assertTrue(c1.hashCode() == c2.hashCode()); assertTrue(!c1.equals(new Object())); }
From source file:net.seedboxer.core.logic.UsersManager.java
public void saveUser(User user) { user.setPassword(DigestUtils.shaHex(user.getPassword())); usersDao.save(user); }
From source file:com.ebay.pulsar.analytics.metricstore.druid.metric.MetricTest.java
public void testInvertedMetric() { String metricName = "InvertedMetricTest"; NumericMetric numericMetric = new NumericMetric(metricName); InvertedMetric invertedMetric = new InvertedMetric(numericMetric); NumericMetric numericMetricGot = (NumericMetric) invertedMetric.getMetric(); assertEquals("Metric Names NOT Equals", numericMetric.getMetric(), numericMetricGot.getMetric()); byte[] cacheKey = invertedMetric.cacheKey(); String hashCacheKeyExpected = "6efcc0886129ea68f8cc255aa390a93d55aecc3c"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); MetricType type = invertedMetric.getType(); assertEquals("Type NOT Equals", MetricType.inverted, type); }