Author: Hiral Patel

How to create and verify JWT Token in Java

Add JWT library in pom.xml <!-- pom.xml --> <!-- JWT Token Creation Library --> <dependency> <groupId>com.auth0</groupId> <artifactId>java-jwt</artifactId> <version>3.4.0</version> </dependency> Create JWT Token public static String generateJWTToken() { String signatureSecret = "SECRET_VALUE_FOR_SIGNATURE"; Algorithm algorithm = Algorithm.HMAC256(signatureSecret); Calendar c = Calendar.getInstance(); Date currentDate = c.getTime(); c.add(Calendar.HOUR, 24); Date expireDate = c.getTime(); String jwtToken = JWT.create() .withIssuer("smoothprogramming") .withSubject("demo") .withAudience("techgeeks") .withIssuedAt(currentDate) .withExpiresAt(expireDate) .withClaim("Claim1", "Value1") .withClaim("Claim2", "Value2") .sign(algorithm); return jwtToken; } Verify JWT Token public static void verifyJWTToken(String jwtToken) { String signatureSecret = "SECRET_VALUE_FOR_SIGNATURE"; Algorithm algorithm = Algorithm.HMAC256(signatureSecret); JWTVerifier verifier = JWT.require(algorithm) .withIssuer("smoothprogramming") .withSubject("demo") .build(); DecodedJWT decodedJWT = verifier.verify(jwtToken); System.out.println("Claim1 is "+ decodedJWT.getClaim("Claim1").asString()); System.out.println("Claim2 is "+ decodedJWT.getClaim("Claim2").asString()); } Code Find the code at Github Repo....

Read More

How to Protect Copyright of Webpage Content

Web is a public place and stealing images/videos/text from your website is one of the common issues. There are precautions available to avoid this issue to some extent, but it is not possible to avoid it completely. In this post, I have discussed some tricks to show how to avoid this issue. Disable Rightclick on a Webpage jQuery is one of the widely used library. You can use following code to avoid right click on a website. Avoiding a rightclick will prevent user from opening Developers Tools in a browser. Remember, user can still open developers tools from browser’s...

Read More

The Most Frequently Used Git Commands

This tutorial compiles list of frequent Git commands for reference purposes. Content Git Connecting to Repo Branch Operations Git add, commit Command Git fetch, merge, and pull Git Reset Git Clean Git Logging Git Connecting to Repo Connect Your Local Repo to Server Following command will connect your local git repo to server. Read More git remote add origin   Branch Operations Create a new branch Following command will create a new branch with [branch-name]. Read More git branch Switch to another branch Following command will to a branch with [branch-name]. Read More git checkout Create a new branch...

Read More

IIFE – Immediately-Invoked Function Expression in Javascript (Simplified)

Functions are a core component of Javascript language. We do a lot of function declaration in our daily programming life. After reading this article, you might use a power of IIFE to encapsulate your business logic and expose minimum methods to a global scope. IIFE is acronym for “Immediately Invoked Function Expression”. It is pronounced as “iify”. The Very simple syntax of IIFE is as below. (function() { /* Code here */ })(); Content Function Declaration vs Function Expression Immediately Invoked Function Expression – IIFE Usage : Encapsulation in JS using IIFE Function Declaration vs Function Expression In javascript,...

Read More

Backup Web Server Files Quickly using gZIP

Have u ever waited for hours to transfer a batch of files from a server to a local machine? I know it is annoying. FTP solutions like FileZilla and WinSCP are very useful for transferring few files between remote machine and local machine. But, it takes too much time to transfer a large number of files. This post shows how you can transfer a large number of files from a server to a local machine quickly by zipping files. Content Method 1: Transfer files using FileZilla Method 2: Quickly Transfer files using Terminal by gZipping Method 1: Transfer Files...

Read More