Password hash using PBKDF2 with HMAC SHA256/ SHA512 in .NET Framework 4.7 and before

Recently I got an requirement from one of my client to generate salted password hash using PBKDF2 and SHA-2 algorithms. But as everyone knows we only have SHA-1 available in .NET framework till now.

Because this was an client requirement so I have to accommodate in my project scope and to do this I got help from a nice guy who made this easy for me. While doing search on google I found this article from that guy. Keep on reading

[SOLVED] jQuery toggle not working for ajax loaded content

Some days ago while doing code for my client, I faced an issue with toggle function of jquery, and realized a fact about this function which I never knew earlier that jquery toggle function does not work for ajax loaded content.

I tried to make it work by using it in different ways but it did not work then after researching on google I came to know that toggle function will not work for content who is added dynamically in body tag. So, I had to find out the alternate of toggle function to get my work done. My code using toggle function was as which was working for content which was not shown through ajax :

$(‘.learn-more’).toggle(function() {
$(this).text(‘Learn less’);
$(‘.campaign-content’).addClass(‘open’);
}, function() {
$(this).text(‘Learn more’);
$(‘.campaign-content’).removeClass(‘open’);
});

So, to make it work for ajax loaded content also, I had to replace toggle function with simple click event and had to add few lines to make it work like toggle and reverse toggle events. So, my updated code is here, with jquery click method which will work same as above code written for toggle and reverse toggle events using jquery toggle function:

$(‘body’).on(‘click’,’.learn-more’,function(){
if($(‘.campaign-content’).hasClass(‘open’)){
$(this).text(‘Learn more’);
$(‘.campaign-content’).removeClass(‘open’);
}else{
$(this).text(‘Learn less’);
$(‘.campaign-content’).addClass(‘open’);
}
});

Here $(‘body’).on(‘click’,’.learn-more’,function(){}); is required because without specifying click event on body tag, the click event will not work for any class or id which is laded through ajax. To distinguish toggle and reverse toggle, I have used open class here, similarly you can use any class like active, inactive etc..

I hope it will help someone and will save someone’s day 🙂

[SOLVED] Rename wp-admin menus

We can easily rename the WP-admin menus labels by using two simple filter hooks i.e. init and admin_menu and assigning the new label in these filters.

To rename the Users menu, you will have to put following code in your theme’s functions.php file :

//Call init action hook
add_action( ‘init’, ‘_init’ );

//Call admin_menu action hook
function _init() {
add_action( ‘admin_menu’, array( $this, ‘create_menu’ ) );
}

/**
* Rename backend navigation.
*/
function create_menu() {
global $navigations;
global $menu;

$menu[70][0] = ‘Registered Users’;
}

Similarly, you can rename any wp-admin menu label by just providing index number of that menu.

If you want to rename submenu then you will have to provide submenu index also  as :

$menu[70][1] = ‘All Registered Users’;

Thus, by using above code, you can simply rename the Users label or other wp-admin menu’s labels easily.

 

addThis share not working for ajax loaded sharing icons

addThis is a robust solution for sharing content to different social platforms. It has plugins also which can be used for this purpose. addThis provides the html or we say toolbox which shows the social icons when we implement that to any page or post. We can also provide the url, title media or description of the page or post within the toolbox which are to be shared through social media icons.

Sometimes, we need to show this toolbox with sharing content through ajax. I we simply show the toolbox html through ajax, then the sharing icon will not display or will not work. To show and to make them work, we will have to reinitialize the toolbox in just single line which is :

addthis.toolbox(‘.addthis_toolbox’);  // Here ‘.addthis_toolbox’ is the the class applied on the toolbox html

Here is an example of showing addthis social icons through ajax request and reinitialize them :

jQuery.ajax({
type: ‘post’,
url: ajax_url,
data: data,
dataType: ‘json’,
success: function(response) {
jQuery(‘#sharing_div’).html(response); // response includes the html of addthis sharing icons
addthis.toolbox(‘.addthis_toolbox’);
}
});

Thus, we can simply reinitialize the addthis sharing toolbox in javascript.

OutSystems: How to set value to expressions

This article is about a new platform which I have explored and did certification. The name of the platform is OutSystems and it is a low code platform. Low code platform means we have to write a little or no code to develop an application and OutSystems is one those low code platform in the industry right now along with Mendix, Appian etc

This post if about a small problem which many of my colleague are facing while exploring OutSystems using its own official courses.

In OutSystems Mobile App Development course there is one class Creating Application Exercise where they have also explained use of expression on any screen and assigning values to it. But there is a little thing which many of the developers think is missing and because of this they face problem while assigning values to expression using mix of a string, method response or any entity value.

One of my friend asked me this problem:

Please see attached screenshot from “Creating Applications Exercise”
So I am stuck at Step 3 (b) on page # 13. I am able to set “GetAppName()” for the Expression but that is not correct.

How to set the Expression to “Hello from “ + GetAppName() ?
There is no screenshot for this step, perhaps it is too simple but I am not able to locate it.

Yes, this is a simple thing to do but because he was doing it first time so got confused. He was not sure how to call method in expression value so he just set  “Hello from ” in value not complete expression including GetAppName() method as shown in below screenshot.

Get list of countries using gravity form plugin

Sometimes, we need to show list of countries in custom form or in simple page. Writing each country name in file is very tedious. If we have installed gravity form in our site then we can create and show dropdown of countries easily with help of gravity form plugin.

In gravity form plugin, there is a class GF_Field_Address in which address fields are created. In this class there is a function get_countries that returns the arrray of countries added in gravity form. We can use this class and method to create our country dropdown in custom form which is not a gravity form.

Thus to create dropdown of country, we have to just write below code :

<select class=”selectpicker” name=”country” >
<?php $countries = GF_Field_Address :: get_countries();
if(!empty($countries) && count($countries) > 0){
foreach($countries as $country){
echo ‘<option value=”‘.$country.'” ‘.(($country==’Canada’)?’selected=”selected”‘ : ”).’>’.$country.'</option>’;
}
}
?>
</select>

If we just want to display, list of country, then we can do as :

<?php $countries = GF_Field_Address :: get_countries();
if(!empty($countries) && count($countries) > 0){
foreach($countries as $country){
echo ‘<li>’.$country.'</li>’;
}
}
?>

Hope, it will save your valuable time…

[SOLVED] Add new columns to the wp-admin users list

One of the most reason of becoming wordpress is as a powerful CMS is its action and filter hooks. One can make modifications in any part of site (both front-end and back-end) using these hooks.

You can also simply add new columns to the users list of wp-admin by using two great action and filter hooks of wordpress i.e. manage_users_columns (filter hook) and manage_users_custom_column (action hook).  Filter manage_users_columns is used to add heading/label of new columns in header of users table and action hook manage_users_custom_column is used to show values of new field for each user in the list.

To add new columns headings and their values for each listed users, you will have to put following code in your theme’s functions.php file :

// Add New Columns Headings
add_filter( ‘manage_users_columns’, ‘wayblaze_modify_user_list’ );
function wayblaze_modify_user_list( $column ) {
unset($column[‘posts’]);
$column[‘organization_name’] = ‘Organization Name’;
$column[‘user_located’] = ‘Address’;
$column[‘subscribe’] = ‘Subscribed to Updates’;
$column[‘contact_telephone’] = ‘Contact Details’;
return $column;
}

// Display New Columns Values for Users
add_action( ‘manage_users_custom_column’, ‘wayblaze_modify_user_cols’, 10, 3 );
function wayblaze_modify_user_cols( $val, $column_name, $user_id ) {
switch ($column_name) {
case ‘organization_name’ :
return ucfirst(get_user_meta( $user_id, ‘organization_name’, true ));
break;
case ‘user_located’ :
return get_user_meta( $user_id, ‘user_located’, true );
break;
case ‘subscribe’ :
return (get_user_meta( $user_id, ‘subscribe’, true )==1 ) ? ‘Yes’ : ‘No’;
break;
case ‘contact_telephone’ :
return get_user_meta( $user_id, ‘contact_telephone’, true );
break;
default:
}
return $val;
}

Thus, one can easily add new columns to the users list o wp-admin using above two filters.

[SOLVED] paragraphs tags not showing in wp content fetched from get_the_content() or paragraphs not showing at front end added from wp-editor

Recently I faced a very wierd issue while adding a post from wp-admin that on adding paragraphs from wp editor, the paragraphs were not showing at front end. The issue was that I have used get_the_content function.

When we use the_content function to show the content o post/page then filters added for the_content also execute ,one of them used to show content with <p></p> tags which are added from wp-editor while adding content. So, when we use get_the_content function, this filter does not execute, so content shows without paragraphs which looks very ugly if there is very large content added.

Sometimes,  situation occurs when we are restricted to use get_the_content function instead of the_content, like when displaying content thorough string concatenation or showing content through ajax. In that cases we have to find out a solution so that content can be displayed with paragraphs also using get_the_content function.

Fortunately, there is a solution of this problem and that is a wordpress function wpautop. This function is used to add paragrapghs into the content which were added while adding content from wp-editor in backend. Thus, this function proved life saving for me 🙂

You can just simply use this function as :

echo wpautop(get_the_content());

And there will be a magic and your content will show now with <p></p> tags automatically. Hope, it will save your day also..

Get current map in event handler of marker click or position changed

Sometimes, we need to used map to get its current zoom level or center coordinates in event handlers. We can easily use map variable which we have created to show map through google map javascript api, but problem occurs when there are multiple map presents on the page, then in event handler we cannot use just map variable, to identify that  the event handler is fired for which map, so we need to use extra function to get map in event handler of google map javascript api.

Google Map API has a function get(‘map’) which can be used to get current map. I have shown here two examples below which shows how to use this function :

// Get map in click event handler of marker
google.maps.event.addListener(marker, ‘position_changed’, function() {
var position = marker.getPosition();
var map_zoom = marker.get(‘map’).getZoom();
});

// Get map in position changed event handler of marker
google.maps.event.addListener(marker, ‘click’, function() {
var map = marker.get(‘map’);
var map_center = map.getCenter();
});

Thus, using above examples, we can easily identify and get the current map on which any action has performed. Hope, it will save your time.