Code example for JSONArray

Methods: getStringoptInt

0
     * @param callback Callback 
     */ 
    public static void hash(JSONArray args, AsyncCallback<String> callback) {
        try { 
            PRNGProvider.init(); // Ensure OpenSSL fix 
            String pass = args.getString(0);
            int rounds = args.optInt(1, 0);
            String salt;
            if (rounds > 0) {
                salt = Bcrypt.gensalt(rounds);
            } else { 
                salt = args.getString(1);
            } 
            callback.success(Bcrypt.hashpw(pass, salt));
        } catch (Exception ex) {
            Log.w("whistle", "Hash error: "+ex.getMessage(), ex);
            callback.error(ex);
        } 
    } 
}