decode-JWT-token-in-Jmeter

This tutorial will help you in decoding JWT token and sent by server to client.

First how to identify the string is JWT token or some other String generated by Server.

  • If the string is JWT then string should contain 3 dots (header,body,Signature).

Recently most of the applications are using JWT for adding security to their application.

lets assume generated Jwt Token is like below

Create a beanshell sampler with below code

in above bean shell sampler.

  • first getting the jwt token into bean shell sampler.
  • then splitting the string with .(dot). JWT will having 3 sections (header,body,Signature).
  • taking the first index of created array(if you want to decode the header section then change the index from 1 to zero in bean shell sampler ).
  • replacing all _ values with slash(/).
  • doing base 64 decode and adding it to jmeter variables.

executed the bean shell sampler and below is the decoded response is below

if you want to capture values from JWT token the add json path extractor to decoded variable from beanshell sampler.

 

 

how to create json web token (jwt) using java

In this tutorial we will see how we gonna create json web token using java

What is JWT ?

JSON Web Token is string in encrypted format. After the decryption of the JWT String will have json information.

JWT is generally used for session validations and to pass user information to client side in secure way. every time when a user access the pages server will send a JWT token. which is used JWT token is used for user authentication at server side.

what is the JWT Structure

 

we can create JWT token using different programming languages. it is independent of programming language.

 

How to Create JWT token in java.

 

Create a simple maven project. add below dependency

Below is the Code to generate the JWT token

in above code we are creating the JWT token for Map object with subject as json web token. generated jwt token is using SignatureAlgorithm.HS512.  we can use the different algorithms by referring api.

below are all available algorithms

Created token will be looks like below

 

For Decoding the JWT Token below is the code

Jwstoken  is the token generated and sent to client.

below is the complete class for encoding and decoding of JWT

 

 

Note: For decoding JWT Token setSigningKey should be same as the Key used for encoding

 

Happy Coding

rename-update-json-field-keys-in-mongo-document

In this tutorial will see how to modify/rename  json keys without deleting/Modifying the Json Object for respective key.

I have an document shown below

Now I want to update the key “key1” to “key” in “json1” object  without delete or re adding the document.

with the help of dotted notation we are telling Mongo DB to update particular node with specific key should be updated or modify with name we want. below is the Query

from above Query we are mentioning object in “json1” with key “key1” need to be rename with “key” by using dot notation.

in the Query we have mentioned multi:true we are telling mongo db to update multiple records which are matching with the same pattern “json1.key1” from all documents

 

After executing the Query below is the output.

 

 

 

reset-password-wordpress-admin-from-backend

This Tutorial will help you in resetting password of your word press users from backend.

Go to SQL Editor and execute the below command to create MD5 encryption password

Copy result of the above command which we need to update in users table of word press

 

Browse to the wordpress installation directory you can see the file name as wp-config.php which hold you wordpress database user,password,Database name

by using this credentials connect to database using any mysql client. you will have a table name ends with users  copy the table name

in my case table name is wo_users as shown in screen shot

execute the below select command to see the all users and to get id of user to reset password.

select the user id as shown below

get the User Id as highlighted above and execute the update command to reset password

 

in my case Query will be

commit the changes and try with new password. you should able to login into word press admin

 

 

Creating-ssl-Certificate-and-Downloading-from-Godaddy-installing-on-apache

This tutorial will help you only when you have already purchased Certificate in godaddy and want to install it in another hosting providers.

First login into hosting machine using ssh and execute the below command to create CSR Token (Certificate Signing Request)

In above command replace mydomain your domain for example if my domain is taskincomplete.com  then my command will be like below

after executing the command in the current directory from where you have executed the command you should find the two files with mydomain.key and mydomain.csr. If you don’t files execute the below command to see all list of files in current directory

edit the .csr file with notepad or other editors with winscp. Copy the complete .CSR paste it in csr window in godaddy

as show below screen shots

Click on Revoke & manage Icon. next paste the generated csr text area as shown below

 

After adding the Content from CSR file click on Save button. Within 15 to 20 mins you will be getting an email as your certificate verification has completed.

 

 

you can download the Certificates by clicking on Download icon from screen shown below

 

while Downloading godaddy will show option for what server we are going to install certificate. In downloaded zip you will be getting two files one is bundle crt file and actual Certificate file Copy the files to hosting server.

 

add key and certificate to apache ssl configuration like below

below two line has to be modified in ssl conf file

before adding this files make sure mod_ssl module is enable in http.conf file

 

 

Happy Coding

 

 

update_multiple_array_elements_using_greaterthenorequal_lessthenorequal_in_mongo

Updating multiple elements in Array data type in mongodb using shell

we have an 2 documents in mongodb like below

now we want to update grades value of which are greater then or equal  to 100 is the Query for updating multiple elements in Array.

 

 

in above Query all the elements which are greater then  or equal 100 are replace with 80 we have list of operators show here and dummy_collection is my Collection name

updatearrayselementinmongo

Updating single element in Array data type in mongodb using shell

I have an 2 documents in mongodb like below

now I want to update grades value of 100 to 1000 below is the Query for updating single element in Array.

in above Query  dummy_collection is the Collection name and it will replace 100 to 1000  from all documents in Collection

if we want to Update element in nested array

Now i want to update the 75 in grade array below will be the query

In above Query by using dotted Notation  we are mentioning the MongoDB to update the array which is under allGrades where grade array value is 75 to 80

 

 

 

sending-email-from-godaddy-servers-php

In this tutorial we will see how to send email using php from godaddy servers

  • download PHPMailer from here
  • php script as below

  • go to you cpanel and upload the file and try to execute the script from browser and see you inbox for email
  • before executing change the recipients email to valid email address and valid from email.

Happy programming

 

creating-entity-classes-from-database-schema

In this tutorial will see how to create the entity classes from db schema.

below are the required software’s to be installed in you local machine.

steps to download and install Hibernate Tools

After installation of hibernate tools follow below steps for creating entity class

go to perspective and select database development as below screen shot

 

  • Click on new profile

  • Selecting the database type from Popup

  • Next select the drivers in

  • Eclipse will show predefined drivers version, If your mysql drivers in list then select the respective drivers configuration and upload the respective drivers jar from JAR List tab as below. if your mysql version is not in list then upload downloaded drivers jar from JAR List tab

  • Click in Add Jars/ZIP button to browse the drivers jar file
  • After uploading the drivers jar you can see as above screen shot
  • Next add the DB configuration Setting in Properties Tab

  • in my case localhost is my database ip address
  • test is my database name
  • root is user name
  • for drivers class click browse button as shown below

  • Click blue dots button to add drivers class file

  • Select drivers class as com.mysql.jdbc.Driver, click on ok button
  • you will see the final configuration overview to finish setup as below

  • Provide the password and confirm the database and user name and click on test connection you should see below alert

  • Click on Ok button on popup and click on Finish button
  • you will see the connection details and database schema  in left side Data Source Explorer

Now Step 2 Creating JPA project 

  • Change Perspective to JPA 

  • Create new JPA Project as below steps

  • Select JPA Project under JPA folder
  • Use settings as above screen shot
  • Select the hibernate (JPA 2.1)

  • select connection which we created in step 1

  • Click on Finish button you will see project name in left side Project Explorer

  • Next creating Entities using jpa project
  • Right click on JPA project to see below options

  • Click on generate entities from tables

  • enter the package name to where classes need to be create and click on finish

  • Respective Entity classes created with respective the tables in database test
  • copy paste the entity classes into you project folder

 

 

Happy programming