<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-7129425532225799174</atom:id><lastBuildDate>Wed, 06 Nov 2024 02:53:34 +0000</lastBuildDate><category>general</category><category>php</category><category>angular</category><category>Javascript</category><category>node.js</category><title>Devhelperworld</title><description>Learn node js, angular, php best practices. A self learning platform to learn web development. Learn modern web development technologies.</description><link>https://devhelperworld.blogspot.com/</link><managingEditor>noreply@blogger.com (Nilesh Sanyal)</managingEditor><generator>Blogger</generator><openSearch:totalResults>26</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-177283489816508314</guid><pubDate>Fri, 08 Nov 2019 09:52:00 +0000</pubDate><atom:updated>2023-03-08T16:09:39.570+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">angular</category><title>The Comprehensive Guide to Angular 8 Reactive Forms</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwCaiCyWbhuPNQzc_RKt8f265mQKdDJ78jEWrcyqhHL87EwbkZq5GOerl_XdsJhGuSvvFhcLsc86gOrE0dRosrjuXAtgUHOnEWTSpvfKsq0RauthDOvo1MvrH_snwMX7UyfWc1Wzfke_8v/s1600/angular-reactive-forms-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms cover image&quot; border=&quot;0&quot; data-original-height=&quot;479&quot; data-original-width=&quot;640&quot; height=&quot;478&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwCaiCyWbhuPNQzc_RKt8f265mQKdDJ78jEWrcyqhHL87EwbkZq5GOerl_XdsJhGuSvvFhcLsc86gOrE0dRosrjuXAtgUHOnEWTSpvfKsq0RauthDOvo1MvrH_snwMX7UyfWc1Wzfke_8v/s640/angular-reactive-forms-cover-image.jpg&quot; title=&quot;Angular Reactive forms cover image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Form validations are vital when building any kind of web application. Depending on the complexity, we can use two approaches; template-driven approach and reactive approach. This article covers angular reactive forms in-depth so that you don&#39;t need to look for other tutorials on the web.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Reactive Forms in Angular?&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If you are familiar with angular&#39;s template-driven approach to validate forms, you know that angular creates &lt;/span&gt;&lt;a href=&quot;https://www.concretepage.com/angular-2/angular-2-formcontrol-example&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;FormControl&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; and &lt;/span&gt;&lt;a href=&quot;https://www.concretepage.com/angular-2/angular-2-formgroup-example&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;FormGroup&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; objects itself after we write our code in the template part (i.e, HTML part) of the code. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But, if we want to have more control over our validation logic, then we should use reactive forms. This approach helps to deal with various complex scenarios. For example, suppose you want to build a form where input fields are displayed depending on the data that you get from the server, then you have only one option, you have to use reactive forms.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When we are using reactive forms, we need to explicitly write code to programmatically handle form validations.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Why Use Angular Reactive Forms?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;There are a number of advantages of using reactive forms in angular, which are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Read/ write the value of the input at any point. (Even before the form is built)&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Define advanced validation rules, supports asynchronous validators that are especially useful when the user is filling out a form and at the same time an HTTP request is sent to the server.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Be notified and react immediately when the value changes.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Access the native HTML form element.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Reset the form.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Reactive forms are significantly easier to test.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Reactive Forms: How They Actually Work?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In order to understand how reactive forms work, at first you need to know the basics of how &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/10/know-everything-about-angular-8-template-driven-forms.html&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;template-driven form&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; works. In a reactive-form based approach, we define the form model by FormGroup and FormControl instances in the component&#39;s class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Then we bind the template to the form model, which means our form is not directly modifying the data model. Now, you may ask the question, how to create a form model?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To create a form model, we need to define a FormGroup directive in our form&#39;s template part. That FormGroup represents the entire form. A FormGroup contains properties that refer to the state of the form itself. To represent the state, we need to provide an instance of the FormControl object as a key-value pair in FormGroup object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Following is the example of defining a form model in the component&#39;s HTML file.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmGGhfU16j6DtZ1bU-lIms2UZk8KNZjBH2VFUG6m2PcW-9DVw_pztT49AL5So8Q_sLhebrHETV8VhOk__R-Z9Z9NbgAVdyCRflI2_ti5-AzXiw-2YljtJ7O8q92OGNo6Ii_Pd35W_6ST0F/s1600/angular-reactive-forms-form-model-template-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive Forms Form Model Template Code&quot; border=&quot;0&quot; data-original-height=&quot;169&quot; data-original-width=&quot;938&quot; height=&quot;114&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmGGhfU16j6DtZ1bU-lIms2UZk8KNZjBH2VFUG6m2PcW-9DVw_pztT49AL5So8Q_sLhebrHETV8VhOk__R-Z9Z9NbgAVdyCRflI2_ti5-AzXiw-2YljtJ7O8q92OGNo6Ii_Pd35W_6ST0F/s640/angular-reactive-forms-form-model-template-code.png&quot; title=&quot;Angular Reactive Forms Form Model Template Code&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;A FormControl object refers to each input element in the form. To bind the input field with the FormControl object we need to specify the FormControlName value in the component&#39;s HTML file. Then we need to refer to that value in the component&#39;s typescript file.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Following is the example of defining a form model in the component&#39;s typescript file. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcjI4N1YSNkS9kIM6TqbcFqWcwSgZ7iJ9qNHtjab20KMjIafqZ0d01SB1sxfPpJqPbmpkREDbx-ykDcGRpIJB-FI0-sM36uyC8cXlx_1bjLTX5bYN-k6v3j1tXz9y2lZwpr115DvGMhBL_/s1600/angular-reactive-forms-form-model-typescript-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive Forms Form Model Typescript Code&quot; border=&quot;0&quot; data-original-height=&quot;243&quot; data-original-width=&quot;465&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcjI4N1YSNkS9kIM6TqbcFqWcwSgZ7iJ9qNHtjab20KMjIafqZ0d01SB1sxfPpJqPbmpkREDbx-ykDcGRpIJB-FI0-sM36uyC8cXlx_1bjLTX5bYN-k6v3j1tXz9y2lZwpr115DvGMhBL_/s1600/angular-reactive-forms-form-model-typescript-code.png&quot; title=&quot;Angular Reactive Forms Form Model Typescript Code&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is The Use of FormBuilder in Angular?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Sometimes, you need to work with large and complex forms, then you need to repeatedly type &quot;new FormControl(&#39;&#39;)&quot;, &quot;new FormGroup({})&quot;. So it becomes a tedious way to represent such large forms. Also, you can hardly read the codes and code debugging may take a long time.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Fortunately, angular helps us out in this regard. You can use FormBuilder class to represent larger, complex forms in such a way so that it is easier to read, understand, debug and maintain.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The following screen-shot is the example of using FormBuilder class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDDMmAw46jz-4GOdjMMHDwUqCDnV8Wel4ch71FTg2EMDZGayt7jSPj0A9ibB31CkPtid6QYrbBvBNjvKynneIz3WbWWn4DTPiWWj2RLVi710Ic3owiDUnBvC43EzxnFvwD7TlgyFwS_1Al/s1600/angular-reactive-forms-form-builder-typescript-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive Forms Form Builder Typescript Code&quot; border=&quot;0&quot; data-original-height=&quot;233&quot; data-original-width=&quot;628&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDDMmAw46jz-4GOdjMMHDwUqCDnV8Wel4ch71FTg2EMDZGayt7jSPj0A9ibB31CkPtid6QYrbBvBNjvKynneIz3WbWWn4DTPiWWj2RLVi710Ic3owiDUnBvC43EzxnFvwD7TlgyFwS_1Al/s1600/angular-reactive-forms-form-builder-typescript-code.png&quot; title=&quot;Angular Reactive Forms Form Builder Typescript Code&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is FormArray?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per angular&#39;s official documentation: &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;it tracks the value and validity state of an array of FormControl, FormGroup or FormArray instances.&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Let me explain what that means. In simple words, FormArray is a class that makes sure that FormControl instances are put together in an array. You can think of the FormArray class similar to FormGroup class that holds objects of FormControl instances.&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/em&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
So, What Are the Differences Between FormArray and FormGroup in Angular?&lt;/em&gt;&lt;/h3&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
&lt;/em&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Simply saying, FormArray is an alternative to FormGroup for managing an unknown number of form elements. FormArray and FormGroup both allow manipulating form elements. &lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;But, if we compare them then FormArray methods are better because it&#39;s methods ensure that the controls are tracked properly in the form&#39;s hierarchy.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;Another point to be noted is that FormArray&#39;s data gets serialized as an array, whereas FormGroup&#39;s data is serialized as an object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
Angular Reactive Forms Example&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;Let&#39;s build a form that will collect user&#39;s various details such as name, email address, age, address, card number, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;Following is the screenshot of the app that we will create.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH1WFGDJPGW2_Kn-0WDK7AhUHDhIRfHzgOSEwUWm8bqu0E897Sx2mkhPeQgS05BmZ8iHG28TT9nxjAz1PJ74WvUpfBD8QwMzwmNSAd0Y-eTeh_t0X01h3PlryrAyjBrfDLha9OFyK3c6oR/s1600/angular-reactive-forms-app-ui.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app ui&quot; border=&quot;0&quot; data-original-height=&quot;585&quot; data-original-width=&quot;1240&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH1WFGDJPGW2_Kn-0WDK7AhUHDhIRfHzgOSEwUWm8bqu0E897Sx2mkhPeQgS05BmZ8iHG28TT9nxjAz1PJ74WvUpfBD8QwMzwmNSAd0Y-eTeh_t0X01h3PlryrAyjBrfDLha9OFyK3c6oR/s640/angular-reactive-forms-app-ui.png&quot; title=&quot;Angular Reactive forms app ui&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;It would be better if you download the complete project by clicking the button below.&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://drive.google.com/file/d/1GsGdxgQpdFr5nVT0jxpQj6hU3dgAygMM/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYNQPH7Nz7oSSTw5WIFyDfQtchmwdX2P7-12NtEbUDBl1z_xVbI91aw65zY4XTm0cGtGsH4cKhNqxAy9-lvrHydd1pygAK3rFnh9caWVaKydMqJ2bYyPlRRtipiM7OtsUDkOM0smUy152c/s320/download_button.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Explanation of app.component.ts File&lt;/em&gt;&lt;/h3&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd4fXtQNzSIo-iec3MM4llVcNTJOUGXg11pSDLr1-rr2cGP7WW_Du53MaPS5qcz6FAfkKgqYrR4dNUyHt1NwYYcPttJXzZPniQZpWGsTR_PSxOMUBD3mkKy8rnXlEETKaYLjvQcGubJ32F/s1600/angular-reactive-forms-app-component-first-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component first code&quot; border=&quot;0&quot; data-original-height=&quot;310&quot; data-original-width=&quot;658&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd4fXtQNzSIo-iec3MM4llVcNTJOUGXg11pSDLr1-rr2cGP7WW_Du53MaPS5qcz6FAfkKgqYrR4dNUyHt1NwYYcPttJXzZPniQZpWGsTR_PSxOMUBD3mkKy8rnXlEETKaYLjvQcGubJ32F/s400/angular-reactive-forms-app-component-first-code.png&quot; title=&quot;Angular Reactive forms app component first code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;In the screen-shot above, we discussed that we need a form group directive inside which we can put individual child elements inside an object. On line 25, we want to send contact information under &quot;contactInfo&quot; object. That&#39;s why we used a form builder object&#39;s group function. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;Inside that function, we wrote the fields that come under &quot;contactInfo&quot; object, for example, name, age, email, address, etc. Similarly, on line 33, we put the card number field under &quot;paymentInfo&quot; object.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieqbb8okfrTlitqQ1zs2pwpWIxAK1IyWVZrolp5W2_mq2ZHzanAJ9fV_1znQUZWS00yOnlTJrVhU5XRs3FLOia_Js4ShV6Nr15XW9-Tl3YUe2sZwUkF6aY0PzNKFXVaggQ-KCHkTZJgq52/s1600/angular-reactive-forms-app-component-second-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component second code&quot; border=&quot;0&quot; data-original-height=&quot;310&quot; data-original-width=&quot;658&quot; height=&quot;187&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieqbb8okfrTlitqQ1zs2pwpWIxAK1IyWVZrolp5W2_mq2ZHzanAJ9fV_1znQUZWS00yOnlTJrVhU5XRs3FLOia_Js4ShV6Nr15XW9-Tl3YUe2sZwUkF6aY0PzNKFXVaggQ-KCHkTZJgq52/s400/angular-reactive-forms-app-component-second-code.png&quot; title=&quot;Angular Reactive forms app component second code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;In the above screen-shot, we have used some built-in validators that angular already provides for us to implement. If these built-in validators are not enough for us, then we should go for implementing our own custom validators.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;For example, we have implemented a custom age validator that takes care of validating ages that must be between 18 to 60. The code snippet for implementing that validator is shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwC9qdWNH4DCJMoU59T5lqGmWZqBLEIcqolQECv_v0eOPuFxXSa8ioIG29kCMNOiA7gXfPZiPdJffBmLf_5X5qtNhVCGz05kEdNAdkf7pB0akcICgf9gC6PgAc6_f9vhI4LaQj9lO_v_o8/s1600/angular-reactive-forms-app-component-third-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component third code&quot; border=&quot;0&quot; data-original-height=&quot;267&quot; data-original-width=&quot;909&quot; height=&quot;116&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwC9qdWNH4DCJMoU59T5lqGmWZqBLEIcqolQECv_v0eOPuFxXSa8ioIG29kCMNOiA7gXfPZiPdJffBmLf_5X5qtNhVCGz05kEdNAdkf7pB0akcICgf9gC6PgAc6_f9vhI4LaQj9lO_v_o8/s400/angular-reactive-forms-app-component-third-code.png&quot; title=&quot;Angular Reactive forms app component third code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;In order to create a custom validator, we need to implement &quot;ValidatorFn&quot; interface. To do so, we created &quot;validateAge&quot; static function inside &quot;AgeValidators&quot; class. We did this so that we can easily call the function without creating an instance of the class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;This function takes AbstractControl as a parameter and returns ValidationErrors if any errors exist, or null if none exists. To represent &quot;ValidationErrors&quot;, we need to return a key-value pair (e.g, &quot;validateAge: true&quot;).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;We have written our logic to implement the custom validator, now we have to display the error message whenever a user enters age that is not between 18 to 60. To display that error message we need to write code as shown in the highlighted portion below.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLkuKXQrv9p2wEuWLrM7KNwS6E4yjcmolVbrRO9_EkUlTsqK6My7_svlvApwDN_nUPqWd5BJDhKz6tbWrK372OtHaDtGb_ynb8OTzN39q2MRGHIW5-kc2ugVniI-6KfvQVvfFch0A-iGbf/s1600/angular-reactive-forms-app-component-fourth-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component fourth code&quot; border=&quot;0&quot; data-original-height=&quot;324&quot; data-original-width=&quot;954&quot; height=&quot;135&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLkuKXQrv9p2wEuWLrM7KNwS6E4yjcmolVbrRO9_EkUlTsqK6My7_svlvApwDN_nUPqWd5BJDhKz6tbWrK372OtHaDtGb_ynb8OTzN39q2MRGHIW5-kc2ugVniI-6KfvQVvfFch0A-iGbf/s400/angular-reactive-forms-app-component-fourth-code.png&quot; title=&quot;Angular Reactive forms app component fourth code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;Finally, we have added functionality so that the user can add multiple addresses. To achieve this, we used FormArray. At first, we defined the FormArray under FormBuilder class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm9tIJaysjIvkdQ84kYiYzO19PKgHzU0d4cSBtQzVG6txIpAnyDwPm11XHMWVVjxsay0z-TcbyNKPOX2lnjYro8XsJ6CDeVemS4qHQNCfeDzfh5JcviIc1MwCsAK2VdXe09TykO6v4K1cT/s1600/angular-reactive-forms-app-component-fifth-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component fifth code&quot; border=&quot;0&quot; data-original-height=&quot;413&quot; data-original-width=&quot;710&quot; height=&quot;232&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm9tIJaysjIvkdQ84kYiYzO19PKgHzU0d4cSBtQzVG6txIpAnyDwPm11XHMWVVjxsay0z-TcbyNKPOX2lnjYro8XsJ6CDeVemS4qHQNCfeDzfh5JcviIc1MwCsAK2VdXe09TykO6v4K1cT/s400/angular-reactive-forms-app-component-fifth-code.png&quot; title=&quot;Angular Reactive forms app component fifth code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;We need to refer to the FormArray instance, in our template file also, we can do that with the help of FormArrayName directive. Then we iterated through all the dynamically added address fields and attached an event called &quot;removeAddress()&quot; to remove address fields at a specific index.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS_uqm4SSY5sR6T2ieEXIRQ5zmDGvb7mtiQcayqjzS6ovS-RnVOlR2UpfbsICoy__ZdjUxh0h4vTRZ4AMF8zlHy7qkzOKdK3zi7eLQUWQDmhDDTFW5tB1PPRnvNJcXllwsHX3mK3SmhiAM/s1600/angular-reactive-forms-app-component-sixth-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component sixth code&quot; border=&quot;0&quot; data-original-height=&quot;379&quot; data-original-width=&quot;956&quot; height=&quot;157&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS_uqm4SSY5sR6T2ieEXIRQ5zmDGvb7mtiQcayqjzS6ovS-RnVOlR2UpfbsICoy__ZdjUxh0h4vTRZ4AMF8zlHy7qkzOKdK3zi7eLQUWQDmhDDTFW5tB1PPRnvNJcXllwsHX3mK3SmhiAM/s400/angular-reactive-forms-app-component-sixth-code.png&quot; title=&quot;Angular Reactive forms app component sixth code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;Outside the loop, we added a button that executes &quot;addFields()&quot; event. &lt;/span&gt;&lt;em style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-style: normal;&quot;&gt;The code snippet for addFields() and removeAddress() is shown below.&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYy4192t8lXh-0rDyplA7ux1oCs6SoOtyelWXrpyWAMzbs3tSHpzzG-rtQfsOSdXh90ekYiYXp8_aAboRwnLum09Pd_EPdQyHLpIs1p0jzE1SWJ0vb12DT1Bq-oTASQ8bjFzJZMvpnQu4a/s1600/angular-reactive-forms-app-component-seventh-code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Reactive forms app component seventh code&quot; border=&quot;0&quot; data-original-height=&quot;259&quot; data-original-width=&quot;775&quot; height=&quot;132&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYy4192t8lXh-0rDyplA7ux1oCs6SoOtyelWXrpyWAMzbs3tSHpzzG-rtQfsOSdXh90ekYiYXp8_aAboRwnLum09Pd_EPdQyHLpIs1p0jzE1SWJ0vb12DT1Bq-oTASQ8bjFzJZMvpnQu4a/s400/angular-reactive-forms-app-component-seventh-code.png&quot; title=&quot;Angular Reactive forms app component seventh code&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
Final Words&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt; I hope that after completely reading this article on angular reactive forms, you have a solid understanding of it. If you have any doubts, you can ask me questions. If this article proves helpful to you, please share it among others. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/11/comprehensive-guide-to-angular-8-reactive-forms.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwCaiCyWbhuPNQzc_RKt8f265mQKdDJ78jEWrcyqhHL87EwbkZq5GOerl_XdsJhGuSvvFhcLsc86gOrE0dRosrjuXAtgUHOnEWTSpvfKsq0RauthDOvo1MvrH_snwMX7UyfWc1Wzfke_8v/s72-c/angular-reactive-forms-cover-image.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-5655666729023029647</guid><pubDate>Sat, 26 Oct 2019 16:40:00 +0000</pubDate><atom:updated>2023-03-08T16:09:41.958+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">angular</category><title>Know Everything About Angular 8 Template Driven Forms</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOdUNosuuHq5lqvJ4WcFkmh2NIhTLwJp15x2m1_cONpPtTbBhDOAoUreQQveiIhsPupHFnqhfw6p5SCdcn7Z-5cXV2EFOb4FnbT0hGReY8w8g7BuCXLwlUECZltlZRmp-xbe8dJ_Eu1enK/s1600/angular-template-driven-forms-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Template Dirven Forms Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;683&quot; data-original-width=&quot;1024&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOdUNosuuHq5lqvJ4WcFkmh2NIhTLwJp15x2m1_cONpPtTbBhDOAoUreQQveiIhsPupHFnqhfw6p5SCdcn7Z-5cXV2EFOb4FnbT0hGReY8w8g7BuCXLwlUECZltlZRmp-xbe8dJ_Eu1enK/s640/angular-template-driven-forms-cover-image.jpg&quot; title=&quot;Angular Template Dirven Forms Cover Image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Angular provides a lot of options to perform validations for the HTML form. To fulfill this need, we can use template-driven forms in angular. This article will walk you through each and every detail regarding the template-driven form validation approach in angular.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s start talking about what actually is angular forms first, then we will dive deeper into template-driven form.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Learn how you can integrate facebook login to your app &lt;a href=&quot;https://www.devhelperworld.in/2019/10/oauth2-facebook-login-part-one.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Why Angular Forms?&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Generally, in every frontend applications, forms play an important and inevitable part. This statement is especially true for huge, enterprise-grade applications. Sometimes, users need to fill out a form that consists of multiple tabs.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To solve this need to handle forms properly, angular provides powerful tools; angular forms. That comes as a built-in feature when we build any angular application from scratch. We don&#39;t need to rely on third-party packages to work with angular forms.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So if anything goes wrong while the user fills out the form, they must be notified what is the reason that causes that problem. To tackle that situation angular itself provides two approaches.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;1. Template Driven Forms&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;2. Reactive Forms&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Template Driven Form in Angular?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You can think of a template-driven form similar to an HTML form. The only difference is that in this type of form, we need to use angular specific directives, events, etc. In this approach, we define the actual template that we want to use in forms. That&#39;s why this approach is called a template-driven approach.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In other words, you can say that in the template-driven form we write our logic, validations, etc. in the template part ( i.e, HTML code).  Template-driven forms are named primarily because the form controls are defined in the template of the component.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As the form is primarily defined in the template layer, it also means that the validation errors are managed through the template.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Before we jump into how you can actually work with template-driven forms, it would be better if you know how template-driven forms actually work behind the scene.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Template Driven Forms: How They Actually Work?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To clearly understand the actual inner-working principle behind template-driven forms first, you need to be familiar with two terms which are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;FormControl&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;FormGroup&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is FormControl in Angular?&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per angular&#39;s official docs: &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;FormControl tracks the value and validation status of an individual form control&lt;/em&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After reading the description about form control from the official site, you may feel confused and thinking of what actually is form control. Let me explain what is form control.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Basically, FormControl is a class that inherits the AbstractControl class in angular. This class can perform various tasks, such as accessing the value, act according to how the user interacts with the form, respond as per the events occurred while the user fills in the form, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, for each input field in our form, we need to create an instance of the FormControl class. With the help of this class, we can check different things. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For example, we can get the value of the input field, we can check if the content of input field has been changed or not, we are also able to check if the field contains a valid value or not.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If we found that the field doesn&#39;t have valid values, we can display validation errors for that particular field.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;There exist different properties in FormControl. These are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;valid&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;invalid&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;dirty&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;pristine&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;touched&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;untouched&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;value&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;errors&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: Lato, sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is dirty in the Angular Form?&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Simply saying, by the term &quot;dirty&quot;, angular is able to detect that the field&#39;s content has been changed by the user.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Pristine in Angular?&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In simple words, &quot;pristine&quot; tells angular that the field&#39;s content has not been modified by the user.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Ok, then tell me about touched and untouched&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;At a glance, you may think that the term &quot;touched&quot; means that the user has not touched the form-field. Yeah, you are right!&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In terms of programming, &quot;touched&quot; means that the user has placed the focus on that particular field. By the term &quot;focus&quot; I mean the user puts the cursor blinking in that field so that he or she can start typing content there.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I guess I don&#39;t have to discuss what &quot;untouched&quot; means.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Let&#39;s talk about the angular form&#39;s error object&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In one sentence, all the errors that result after the user fill out the form are stored in the error object. These errors are stored in form of key-value pairs. In which the field name itself is the key and the error message is the value for that corresponding key. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Form Group in Angular?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;According to angular&#39;s official website: &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;FormGroup tracks the value and validity state of a group of FormControl instances.&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Let&#39;s discuss what is form group and its purpose. FormGroup is a class that represents a group of controls in a form. Each of the forms refers to a form group.&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Technically we can say that each form group can consist of multiple form control elements in angular. As we know earlier, we can easily access each form control elements various properties (e.g, valid, invalid, dirty,  pristine, etc.).&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
Template Driven Forms: A Simple Example&lt;/h2&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;Let&#39;s assume we want to build a checkout form for an e-commerce store that takes the user&#39;s first name, last name, address, etc. under the Billing Info section. Then in Payment Info section user enters details such as the name on the debit card, card number, expiry date, CVV number, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;Please note that angular material is used to build the user interface of this application. If you don&#39;t know about it, you can check out this article &lt;/span&gt;&lt;a href=&quot;https://medium.com/@ismapro/first-steps-with-angular-7-with-angular-cli-and-angular-material-d69f55d8ac51&quot; style=&quot;box-sizing: inherit; color: #007fac; font-style: normal; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;Following is the screenshot of the app.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwKiKkXRya_47qNbJdx-xmKdVIjtnK9hpRISbGLC4fuIPu2I7DhayRcuYBcnAqJCOVUPeLnNa44z5wJAHHKMhkdi_BZWX7UfUub9A74sNxlpWTprLdkrQ_ChBn7F1nGW8nby4YOTndiw2Y/s1600/angular-template-driven-forms-ui.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Template Driven Forms UI&quot; border=&quot;0&quot; data-original-height=&quot;616&quot; data-original-width=&quot;1341&quot; height=&quot;292&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwKiKkXRya_47qNbJdx-xmKdVIjtnK9hpRISbGLC4fuIPu2I7DhayRcuYBcnAqJCOVUPeLnNa44z5wJAHHKMhkdi_BZWX7UfUub9A74sNxlpWTprLdkrQ_ChBn7F1nGW8nby4YOTndiw2Y/s640/angular-template-driven-forms-ui.png&quot; title=&quot;Angular Template Driven Forms UI&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To follow along with this tutorial, download the complete project by clicking the button shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://drive.google.com/open?id=1Y5M_bZaEE0hFWhZGac2cUfv-BIG4o6EQ&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYNQPH7Nz7oSSTw5WIFyDfQtchmwdX2P7-12NtEbUDBl1z_xVbI91aw65zY4XTm0cGtGsH4cKhNqxAy9-lvrHydd1pygAK3rFnh9caWVaKydMqJ2bYyPlRRtipiM7OtsUDkOM0smUy152c/s320/download_button.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Explanation of app.component.html File&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjboh_lZDK1EW4JU3rJr-EufMOvjVYbiuQR50uyxpNon2qyygDx8z2vMD7hKt-ex6sOOXmnp0M8QGCSo9hqH703rXtfUYD7u3yZYHn25wuIECMZ0wO9V7icbcFhfWWP5ZtqFM98EoX3U0Nl/s1600/angular-template-driven-forms-ui-code-snippet-folded.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Template Driven Forms UI Code Snippet Folded&quot; border=&quot;0&quot; data-original-height=&quot;421&quot; data-original-width=&quot;839&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjboh_lZDK1EW4JU3rJr-EufMOvjVYbiuQR50uyxpNon2qyygDx8z2vMD7hKt-ex6sOOXmnp0M8QGCSo9hqH703rXtfUYD7u3yZYHn25wuIECMZ0wO9V7icbcFhfWWP5ZtqFM98EoX3U0Nl/s640/angular-template-driven-forms-ui-code-snippet-folded.png&quot; title=&quot;Angular Template Driven Forms UI Code Snippet Folded&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet of the app.component.html file, we have created two expansion panels. The main purpose of it is to represent similar form elements together as a single entity. First of the panel will hold all billing information, while the second one will hold all details regarding the payment information that the user will provide to make the payment.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We also applied a directive called &quot;ngForm&quot; that is provided by angular automatically. Its main purpose is to keep track of the form&#39;s overall validation status. But, under the hood, it creates a FormGroup instance at the top level.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We want to properly handle the validation for each individual form elements. To achieve this, we have created a template variable &quot;userForm&quot; and assigned ngForm to that variable. After doing that, we are able to get values for properties like dirty, touched, pristine, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjelEZEDpWd1ssLdveOviTTiWJrPFU-kULiZzwvL840ISNuQSojLV-Kxke5XsrfY8liGOVVMYVbbfXVUh0Lg1P5lFZOazYMZ5_6NMB08mo4pjlep5MqiQQaeNNqZeqEeSFzaamkHhtaaHXX/s1600/angular-template-driven-forms-first-expansion-code-snippet.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Template Driven Forms First Expansion Code Snippet&quot; border=&quot;0&quot; data-original-height=&quot;514&quot; data-original-width=&quot;871&quot; height=&quot;376&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjelEZEDpWd1ssLdveOviTTiWJrPFU-kULiZzwvL840ISNuQSojLV-Kxke5XsrfY8liGOVVMYVbbfXVUh0Lg1P5lFZOazYMZ5_6NMB08mo4pjlep5MqiQQaeNNqZeqEeSFzaamkHhtaaHXX/s640/angular-template-driven-forms-first-expansion-code-snippet.png&quot; title=&quot;Angular Template Driven Forms First Expansion Code Snippet&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Here, we have applied a &quot;ngModel&quot; directive to the input field that asks user to enter his or her first name. In template driven approach, angular will create a FormControl object and associate the input field with that object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Also, we must set name property for that input field, it is mandatory to do so. Otherwise, angular will not be able to distinguish that input field.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Later, we want to make sure that if user did not fill up the first name, the user will be notified that he or she forgot to do so. For this purpose, we have created a local reference variable called &quot;fName&quot; and stored &quot;ngModel&quot; in that variable.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We are using HTML5&#39;s built-in &quot;required&quot; validator.  Then with the help of ngIf directive, we check to see if first name field has focus and it is invalid. If these conditions are true we set the show user a message &quot;You must enter first name&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;With the help of &amp;lt;mat-error&amp;gt; angular material element, we checked to see if &quot;firstName&quot; input field contains any required type of error or not. Here the question mark (&quot;?&quot;) symbol denotes optional property. We used it to indicate if errors property exists then we want to make use of that property. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Now, you may wonder why &quot;ngModelGroup&quot; directive is used. Let&#39;s explain the main role of it. Sometimes, we may need to send a complex object to the back-end after submitting the form. For this purpose, angular make use of this directive.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For example, in this example, we want to send billing information as well as payment information to the back-end. Under billing, we have fields such as first name, last name, gender, etc. Inside payment, we have card number, CVV number, etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, it logically makes sense to send billing data inside the &quot;billing_information&quot; object and payment data inside the &quot;payment_information&quot; object. That&#39;s why, we created two div elements and assigned first ngModelGroup&#39;s value &quot;billing_information&quot; and second value as &quot;payment_information&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Explanation of app.component.ts File&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3mwNfyV87FZNZAypmFQQMpujjul7eaIEbhcXHs9ALq3aftcIiPXZ9U-k9iLfgHJPiCaTHhLvtkD_GVyN3TAfkM38LFuxr0ET8sdsK5nLh2sebzft7fYrPePTL_GPmw7Ekav9t2JrWLTwp/s1600/angular-template-driven-forms-app-component-logic.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Template Driven Forms App Component Logic&quot; border=&quot;0&quot; data-original-height=&quot;563&quot; data-original-width=&quot;669&quot; height=&quot;538&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3mwNfyV87FZNZAypmFQQMpujjul7eaIEbhcXHs9ALq3aftcIiPXZ9U-k9iLfgHJPiCaTHhLvtkD_GVyN3TAfkM38LFuxr0ET8sdsK5nLh2sebzft7fYrPePTL_GPmw7Ekav9t2JrWLTwp/s640/angular-template-driven-forms-app-component-logic.png&quot; title=&quot;Angular Template Driven Forms App Component Logic&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Here, we are handling the &quot;ngSubmit&quot; event emitted by the &quot;ngForm&quot; directive. We simply wrote the code to display the submitted data in the browser&#39;s console window.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The screen-shot of the submitted data is shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnMlAYonxats5h1NRgnO3hZWc7jNq77BpyeVWIUF3PMVQFkAowAsD3gwedKv2aeja514EIgLYfkGiYoYLsJBIEjoKwFgHHDOKLuNHE_8dUanzRub4SbBUNJPlFq4UDt9Pua3gxl4v4m57t/s1600/angular-template-driven-forms-app-output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Angular Template Driven Forms App Output&quot; border=&quot;0&quot; data-original-height=&quot;474&quot; data-original-width=&quot;1338&quot; height=&quot;226&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnMlAYonxats5h1NRgnO3hZWc7jNq77BpyeVWIUF3PMVQFkAowAsD3gwedKv2aeja514EIgLYfkGiYoYLsJBIEjoKwFgHHDOKLuNHE_8dUanzRub4SbBUNJPlFq4UDt9Pua3gxl4v4m57t/s640/angular-template-driven-forms-app-output.png&quot; title=&quot;Angular Template Driven Forms App Output&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Final Words&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; I hope that after reading this article on angular template-driven forms, you have a clear concept in it. If you have any doubts, you can ask me questions. If anyhow this article proves beneficial to you, please share it among others. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/10/know-everything-about-angular-8-template-driven-forms.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOdUNosuuHq5lqvJ4WcFkmh2NIhTLwJp15x2m1_cONpPtTbBhDOAoUreQQveiIhsPupHFnqhfw6p5SCdcn7Z-5cXV2EFOb4FnbT0hGReY8w8g7BuCXLwlUECZltlZRmp-xbe8dJ_Eu1enK/s72-c/angular-template-driven-forms-cover-image.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-8445546892917029054</guid><pubDate>Tue, 08 Oct 2019 17:18:00 +0000</pubDate><atom:updated>2023-03-08T16:09:44.443+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">angular</category><category domain="http://www.blogger.com/atom/ns#">node.js</category><title>Implementing Oauth2 Social Login With Facebook Part 2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinif5Yc1vGTpj4dJ5MzC7zQjxePHLrtDm76Z60tgNmUilUmUIuez2DbwJarVNB4jLdCM60M7JJ6HDyCBEVu4ilzPMak7_5Bcd-s7Lr9WMl38DeAn7h13qUpdLtH-WUSWnrmwcJ2BQzsUrJ/s1600/oauth2-facebook-cover-photo.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Cover Photo&quot; border=&quot;0&quot; data-original-height=&quot;1067&quot; data-original-width=&quot;1600&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinif5Yc1vGTpj4dJ5MzC7zQjxePHLrtDm76Z60tgNmUilUmUIuez2DbwJarVNB4jLdCM60M7JJ6HDyCBEVu4ilzPMak7_5Bcd-s7Lr9WMl38DeAn7h13qUpdLtH-WUSWnrmwcJ2BQzsUrJ/s640/oauth2-facebook-cover-photo.jpg&quot; title=&quot;OAuth2 Facebook Cover Photo&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the previous part of this article, we discussed what is OAuth2 and how OAuth2 helps to integrate social login to our application in an easy approach. Also, we discussed how you can use OAuth2 to create a facebook application on their official website that will later come handy to continue building our node js application.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This article is the second part of implementing social login with facebook. If you missed that article, you can read it &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/10/oauth2-facebook-login-part-one.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
OAuth2 Workflow For Facebook Login Application&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9_dyAEpF87Yv-obzmhy8mC4qBCjq4EzyMPaxd7-7nTJ2XiuLfZFRb4MbCBEEs-ht9vX54XstrP62wjsZ-iPzQ6MCDfHUbOwgHDqKf7M4qJfSWgWgF2mR0uOEPcADS-tM1n4Isb7NzPtGa/s1600/oauth2-facebook-login-actual-workflow.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Login Actual Workflow&quot; border=&quot;0&quot; data-original-height=&quot;531&quot; data-original-width=&quot;864&quot; height=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9_dyAEpF87Yv-obzmhy8mC4qBCjq4EzyMPaxd7-7nTJ2XiuLfZFRb4MbCBEEs-ht9vX54XstrP62wjsZ-iPzQ6MCDfHUbOwgHDqKf7M4qJfSWgWgF2mR0uOEPcADS-tM1n4Isb7NzPtGa/s640/oauth2-facebook-login-actual-workflow.png&quot; title=&quot;OAuth2 Facebook Login Actual Workflow&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s discuss the workflow of the application as per the above screenshot. To create the application we require 3 main parties involved. The first one is the angular application, second is the Facebook server itself and last but not least the server which will act as a REST API written in Express JS Framework. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;At first, users will try to login to our application. To do that they will click on the &quot;Login With Facebook&quot; button. Then a dialog will open that will ask the user to enter their Facebook credentials. Finally, the user gives permission to access some of their Facebook data. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After allowing access, our angular client gets the access token from the Facebook server. For now, we can easily access facebook data from the angular client application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But, the backend server needs to know that. In order to do so, the angular application sends a request to the backend server with the access token. To verify that token the backend sends a verification request directly to the Facebook server.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If the Facebook server finds the token to be a valid one, it sends back the user&#39;s profile information. After receiving that data, the backend express js server verifies that the user profile data is correct and finally creates a new user in the application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If the user already exists in the backend, the user profile will be updated instead.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Then the backend server will create a JSON web token that will identify the user. Backend returns that token as a response to the client application. The client app will store that token so that when sending requests to the server it can send the token along with the request.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What We Will Be Building&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We will create an application that will have a login with facebook functionality. In order to understand the overall functioning of this app, you need to have fundamental knowledge in Angular and Node JS.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To follow along with this tutorial, download the project file by clicking the button shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://drive.google.com/file/d/1lnY3wroNuiIhlbkzR0bVOmiTErE1z1NF/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYNQPH7Nz7oSSTw5WIFyDfQtchmwdX2P7-12NtEbUDBl1z_xVbI91aw65zY4XTm0cGtGsH4cKhNqxAy9-lvrHydd1pygAK3rFnh9caWVaKydMqJ2bYyPlRRtipiM7OtsUDkOM0smUy152c/s320/download_button.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Then make sure you install &lt;/span&gt;&lt;a href=&quot;https://nodejs.org/en/download/&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;node js &lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;and &lt;/span&gt;&lt;a href=&quot;https://www.mongodb.com/download-center/community&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;MongoDB&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. After downloading is finished extract the rar file, then open two command prompts or terminal windows. In one terminal navigate to the &quot;frontend&quot; folder. In another one, navigate to the &quot;backend&quot; folder. You need to start your MongoDB database too.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Open &quot;.env&quot; file in &quot;backend&quot; folder, put actual values in &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: red; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;FACEBOOK_APP_ID&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; and in &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: red; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;FACEBOOK_APP_SECRET&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; environmental variables. To get those values you need to put your app id and app secret keys that were generated when you created a Facebook application on facebook developer&#39;s website.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; You may have to change other values as per your needs. For example, if you want to change the database name, you can do so by changing the value for &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: red; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;DB_DATABASE&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; variable.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The terminal where you opened the &quot;frontend&quot; folder run this command &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;npm start&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;. In another terminal where the &quot;backend&quot; folder is opened, run &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;npm run dev-server&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Building The Frontend With Angular&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s start building the application&#39;s frontend part with Angular. To connect our angular app with Facebook, we need to use Facebook&#39;s Javascript SDK. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For this we need to add the link to that SDK, we can do so with the help of script tag in index.html file as shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/f3ffddccd807ad8fff317a4ea9d11553.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Adding Bootstrap To The Project&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Open another terminal, navigate to the location of the &quot;frontend&quot; folder. Run &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;npm install bootstrap&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; command, this will install bootstrap locally. Also, you need to add font-awesome for adding facebook icon to the login button. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Keep that terminal open, we will need this terminal when we will build our angular application. For doing this, run &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;npm install font-awesome&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;. Then add that dependency in the angular.json file as shown below in the code snippet.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu4OBEqn7Lmg9LxoUbCPgegg1n7QjNmAbhRF-6EsvO8JBW73eP_C2Bn5o8pgXlJF9uBqDjFfsp3Fn9hIC9Ds7Y_-AM3eesBGvB_8DLj4Bt-8p27kCF6Ar_3R233CXIPjNnydtfIIBmG-rA/s1600/oauth2-facebook-login-frontend-dependency.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Login Frontend Dependency&quot; border=&quot;0&quot; data-original-height=&quot;227&quot; data-original-width=&quot;631&quot; height=&quot;230&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiu4OBEqn7Lmg9LxoUbCPgegg1n7QjNmAbhRF-6EsvO8JBW73eP_C2Bn5o8pgXlJF9uBqDjFfsp3Fn9hIC9Ds7Y_-AM3eesBGvB_8DLj4Bt-8p27kCF6Ar_3R233CXIPjNnydtfIIBmG-rA/s640/oauth2-facebook-login-frontend-dependency.png&quot; title=&quot;OAuth2 Facebook Login Frontend Dependency&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating Login Component For Our OAuth2 Facebook Application&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When we will run our application, the user will see the login page. For that purpose, we need to create a login component. Run &quot;ng g c login&quot; in the terminal window. Open login.component.html file and add the following codes for designing the login component.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/7b1bc3f831ff024aaadb462086457680.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, &lt;b&gt;fbLogin()&lt;/b&gt; method is called when the &quot;&lt;i&gt;Login with Facebook&lt;/i&gt;&quot; button is clicked. Let&#39;s write what will happen when that button will be clicked. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/80727b27838f553efdd2299bb7887523.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, the &lt;b&gt;fbLogin()&lt;/b&gt; method calls user service that performs an API call to our backend server and returns the promise object. After getting that promise object, the user is redirected to the dashboard page.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating User Service For Our OAuth2 Facebook Application&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/70336af2c61851d4aebdf1faeed4268b.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This user service will communicate with the Facebook server and our backend server. This service is responsible for performing the following tasks.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Making sure so that users can log in with their Facebook profile.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Logging users out.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Checking if users are logged in or not.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Getting details of currently logged in users.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To create the service issue this command in terminal. &quot;ng g s user&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Explanation of the Code Snippet&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the UserService typescript class, a library is initialized from the facebook javascript SDK. Here, we need to replace &quot; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: red; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;YOUR_FACEBOOK_APP_ID &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; with the application id that we got when we created the Facebook application on the facebook&#39;s developers website.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In fbLogin method, we are calling FB.login method that will display a dialog window, so that users can log in. If users are not logged in this dialog will be displayed.  This dialog also asks users to allow the application to access user&#39;s data.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The response coming from &lt;b&gt;FB.login&lt;/b&gt; method contains information whether the user is logged in or not and if they have allowed our application to access their data.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After getting response we call our backend to log in to the application. If user is able to log in to the backend, we will get a token as a response from the backend server.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We stored that token in local storage. So that, later when we will send a request to the backend, we are able to send the token alongwith the request. The main role of the token is to identify the current user.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The  &lt;b&gt;getCurrentUser&lt;/b&gt; method gets the data of currently logged in user from the server.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The &lt;b&gt;logout&lt;/b&gt; method removes the token from the browser&#39;s local storage.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating Dashboard Component For Our OAuth2 Facebook Application&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Run &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;ng g c dashboard&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; in the terminal to create dashboard component. Code snippet for dashboard.component.html is shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/f3302b2d76c64b939b523dc29bd99898.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, we are displaying currently logged in user&#39;s email address.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s write the code for getting currently logged in user&#39;s details. Code snippet for dashboard.component.ts file is displayed below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/3d92c6685639d9c2657e00914e1aa2fc.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the code snippet, at the initialization phase of the dashboard component, we are loading user&#39;s data. We do so by calling the user service&#39;s getCurrentUser method inside &lt;b&gt;ngOnInit&lt;/b&gt; method. After that we store user&#39;s data in currentUser object. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I guess, you remembered this currentUser object, it is used in dashboard component&#39;s html page to access currently logged in user&#39;s email address.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the logout method, we are calling user service&#39;s logout method. After user is successfully logged out, they are redirected to the &quot;&lt;b&gt;login&lt;/b&gt;&quot; route.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating Guards For Our OAuth2 Facebook Application&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s assume we want to implement some sort of functionality such that we will allow only those users to visit the dashboard page who are already logged in. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We won&#39;t allow users who are not logged in and will redirect them to the login page when they will try to visit the dashboard page.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To add this functionality to an angular application, a guard is used.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;There exist four types of guards in angular, these are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;CanActivate: This guard decides whether a route can be activated or not. If this guard returns true navigation will continue to otherwise navigation will not continue to the next route.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;CanActivateChild: It decides if a child route can be activated.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;CanDeactivate: It is helpful to decide if a route can be deactivated.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;CanLoad: It helps to decide whether a module can be lazy-loaded or not.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We need to add two guards in this application.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To create the auth guard type &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;ng g g auth&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; in the terminal window. The code snippet for AuthGuard is below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/c658a0746a0b259988a2148dc266281a.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above snippet, AuthGuard checks if the user is logged in or not. This is possible with the help of UserService&#39;s isLoggedIn method. If the user is logged in, we will resolve the promise, and allow the user to visit the dashboard page.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Otherwise, the user will be redirected to the login page.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Similarly to create another guard named anonymous, type &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;ng g g anonymous&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; in the terminal. The code snippet for it is displayed below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/21be766455bb313076d60591129ed43a.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the code above, AnonymousGuard is used for checking if the user is not logged in.  Its functionality is defined in UserService&#39;s &lt;b&gt;isLoggedIn&lt;/b&gt; method. If the user is logged in the user will be redirected to the dashboard page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Defining Routes For Our OAuth2 Facebook Application&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/2c9c2a372dfe731b1212986c01a1a756.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the route file, we define what component angular will load when a specific route is being accessed by the user. For example, for visiting the login route the LoginComponent will load. When a user visits the application without any path, in that scenario, the LoginComponent will be loaded by default.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Explaining The AppModule&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/b8cb0924acd3cc366de02b952eeaf24f.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, we have used a new module named &quot;&lt;i&gt;auth0/angular-jwt&lt;/i&gt;&quot;, so that we can automatically attach a JSON web token as an authorization header. The browser attaches this header when the application sent the HTTP request. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The main role of &lt;b&gt;tokenGetter&lt;/b&gt; function is to get the JSON web token from the of the current user from the browser&#39;s local storage. Angular fetches this token with the key &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;id_token&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Building The Backend With Express JS&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s create the backend part of our application. We will be using the Express Js framework for creating the REST API. For storing user information we will use a MongoDB database. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Project Dependencies At a Glance&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We are using the lightweight non-opinionated framework of Node i.e, Express Js. The &lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;body-parser&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; module will take care of handling incoming request bodies with a middleware. The &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;jsonwebtoken&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; module will handle the JSON web token.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;passport&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; module will take care of authentication and &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;passport-facebook-token&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; will specifically handle the Facebook authentication. &quot;mongoose&quot; will communicate with MongoDB database. The &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;dotenv&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; module facilitates the use of environmental variables and the &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;cors&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; module will help to enable &lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Cross-origin_resource_sharing&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;CORS&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; on our server.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating The Node Server&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/fc7bdfb0d53cfbd496c5173c9664ade1.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, at first all the dependencies are declared, then while configuring the CORS middleware in line number 23, we make sure that the &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;x-auth-token&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; header is visible to the angular client.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This step is necessary otherwise our angular client would ignore this custom header. It is done with the &quot;&lt;b&gt;exposedHeaders&lt;/b&gt;&quot; property.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To connect with the MongoDB database, in line number 12, we have used the IIFE (Immediately Invoked Function Expression). If you don&#39;t know what it is, you can know more about it &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/09/javascript-callback-in-depth.html&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In line number 36, we want to validate &lt;b&gt;JWT&lt;/b&gt;(&lt;i&gt;JSON Web Token&lt;/i&gt;)  in every frontend request. If we find that the JSON Web Token is valid, then &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;req.auth&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; will be set with the decoded JSON object. Later the middleware that will perform authorization will use this object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In line number 47, the user data is fetched by user id, and then that user data is stored in the request object within the &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; property. Finally in line 57, to extract only selected data from the user object, we removed two properties namely &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;facebook&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; and &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;__v&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating The user Routes File&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/e76257f89be80a8d6596a9176c005520.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In line number 8, we invoked the &lt;b&gt;passportConfig&lt;/b&gt; function, which has the actual implementation of how passport js module will handle facebook login functionality.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In this file, we have defined the route where we have configured to use passport js&#39;s token-based strategy for authenticating with Facebook login. That&#39;s why, in line number 13, you will notice that we have set to authenticate with &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;facebookToken&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;, we set &quot;session&quot; as false.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Then we invoked the userController&#39;s &lt;b&gt;facebookOAuth&lt;/b&gt; function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating The passport.js File&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/da6661d4ec5dd780fd37f976f9d70d64.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In this file, we are checking if any user exists in the database, if one user is found, we simply return the user object. Otherwise, we create a new user and then return that user object instead.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating users Controller File&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/43d753efe4866f8a7334dd8c5adb4479.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, we are storing the user&#39;s id in a token. That token is known as JSON Web Token (JWT). After generating JWT, we send it to the frontend (i.e, angular application). We send the token with the help of a custom header i.e, &quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: blue; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;x-auth-token&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating user Model File&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/3a1b44f8718677b24abcc6175924403c.js&quot;&gt;&lt;/script&gt;

&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Conclusion&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Finally, you have a complete application that enables users to login with their existing Facebook account. You have created that app that follows the OAuth2 protocol in order to build this application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For developing the frontend part we used Angular. Then the frontend will communicate with a backend that is built using Express Js. If you find this article helpful, consider sharing this with others. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/10/oauth2-facebook-login-part-two.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinif5Yc1vGTpj4dJ5MzC7zQjxePHLrtDm76Z60tgNmUilUmUIuez2DbwJarVNB4jLdCM60M7JJ6HDyCBEVu4ilzPMak7_5Bcd-s7Lr9WMl38DeAn7h13qUpdLtH-WUSWnrmwcJ2BQzsUrJ/s72-c/oauth2-facebook-cover-photo.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-3617245585710669687</guid><pubDate>Sat, 05 Oct 2019 10:40:00 +0000</pubDate><atom:updated>2023-03-08T16:09:46.804+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">angular</category><category domain="http://www.blogger.com/atom/ns#">node.js</category><title>Implementing Oauth2 Social Login With Facebook Part 1</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR__ifG7ukjIVTaNVUplsW_dxXQkNILx05AQrI1IBxu3BzsvCVwT2wlRFqYQ3YEWwr15f5hlXBWq0OknB7oOlgE76-FgCjHlkmS8xXx0rJNJ8yrjhYDBFkIG-Vg0yS9zsEP-DYKhaokZko/s1600/oauth2-facebook-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Oauth2 Facebook Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;1005&quot; data-original-width=&quot;1600&quot; height=&quot;402&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR__ifG7ukjIVTaNVUplsW_dxXQkNILx05AQrI1IBxu3BzsvCVwT2wlRFqYQ3YEWwr15f5hlXBWq0OknB7oOlgE76-FgCjHlkmS8xXx0rJNJ8yrjhYDBFkIG-Vg0yS9zsEP-DYKhaokZko/s640/oauth2-facebook-cover-image.jpg&quot; title=&quot;Oauth2 Facebook Cover Image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In this article, you will have a clear understanding of how to use oauth2 authentication to implement facebook login with node js. Adding social login to your application has a lot of advantages. First of all, users of your application don&#39;t need to fill up a long registration form containing 10 or even more input fields. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Also while attempting to login to any application, they often forget their password. They, don&#39;t want to go through the password recovery process, as they find it tedious to do so.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The solution to this problem is if are able to register and login users to our application with their social network accounts in which they already have accounts. We can implement this functionality with the help of an authentication scheme known as &lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/OAuth#OAuth_2.0&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;Oauth2&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You can check out my article on the callback function &lt;a href=&quot;https://www.devhelperworld.in/2019/09/javascript-callback-in-depth.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Oauth2&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per the official site of Oauth:  &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;OAuth 2.0 is the industry-standard protocol for authorization. OAuth 2.0 supersedes the work done on the original OAuth protocol created in 2006. OAuth 2.0 focuses on client developer simplicity while providing specific authorization flows for web applications, desktop applications, mobile phones, and living room devices. &lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;In simple words, it is an authentication and authorization scheme in which users on the internet are able to access their information on other websites, without providing their account credentials ( username and/or password).&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Only one requirement exists; that is, the user must authorize the application to access their data for a selected OAuth provider.&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
Why OAuth2 is Used&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; font-style: normal; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
Users don&#39;t need to remember their credentials&lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Users can sign up or log in to any application that are using OAuth2 without using any credentials such as email id and/or password. They simply need to authorize the application to access their information for a selected OAuth provider. This step is done for one-time only.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
&lt;/span&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; font-style: normal; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
Prevents security holes&lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;In the Oauth2 mechanism, the user doesn&#39;t provide passwords to sign in or sign up for the application. So, from the development point of view, developers don&#39;t need to store a user&#39;s password. This, in fact, prevents inappropriate use of storing passwords.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; font-style: normal; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
Developer friendly&lt;/h4&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;Developers can easily implement oauth2 in an application. They just need to go through the technical documentation for the specific OAuth provider. For example, if sign in and/or sign up with facebook functionality needs to be implemented, the developer needs to visit the official docs page for facebook OAuth provider.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; font-style: normal; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
Ability to handle non-web clients&lt;/h4&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;In the OAuth2 authorization process, the program that sends requests to the authorization server is known as the client. The client can be a browser, a mobile app or any other device. That&#39;s how OAuth2 is able to handle non-web clients also.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
How OAuth2 Works&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23; font-style: italic;&quot;&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;Before discussing how OAuth2&#39;s working principle, it would be better if we discuss the key roles played by each component in this protocol.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; color: #191e23; font-style: normal; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Resource Owner: It refers to the user who gives permission to authorize an application in order to access their account. The authorization&#39;s scope determines the application&#39;s access to the user&#39;s account.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Resource or Authorization Server: The authorization server is responsible for verifying the identity of the user. Resource server refers to a server that hosts the protected user&#39;s accounts.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Client: It refers to the application that accesses the user&#39;s account. But, in order to do so, it must be authorized by the user, and that authorization process must go through a validation process carried by an API.&lt;/li&gt;
&lt;/ol&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
Now, you know the roles played by each component; let&#39;s discuss the overall workflow of OAuth2 in simple words.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;color: #191e23; margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOLpRaJpmpIXvSDKP3bAmO8InJAsB_ORtdpvlblUWcJib91feZ5PSGAxSvt5elD0O37WDszBPqVj0TpTT8o6au1Zf96g3uF18B_pYST-T09WQyljkzd80ErTU1nNYgMegZQG25qAeymI45/s1600/oauth2-facebook-workflow.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Workflow&quot; border=&quot;0&quot; data-original-height=&quot;479&quot; data-original-width=&quot;700&quot; height=&quot;436&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOLpRaJpmpIXvSDKP3bAmO8InJAsB_ORtdpvlblUWcJib91feZ5PSGAxSvt5elD0O37WDszBPqVj0TpTT8o6au1Zf96g3uF18B_pYST-T09WQyljkzd80ErTU1nNYgMegZQG25qAeymI45/s640/oauth2-facebook-workflow.png&quot; title=&quot;OAuth2 Facebook Workflow&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;color: #555d66; font-family: &amp;quot;noto serif&amp;quot;; font-size: 13px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;a href=&quot;https://commons.wikimedia.org/wiki/User:Guenter.kolb&quot; rel=&quot;noreferrer noopener&quot; style=&quot;box-sizing: inherit; color: #007fac; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 13px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;Guenter.kolb&lt;/a&gt;&lt;span style=&quot;color: #555d66; font-family: &amp;quot;noto serif&amp;quot;; font-size: 13px; white-space: pre-wrap;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Protocol-Flow.png&quot; rel=&quot;noreferrer noopener&quot; style=&quot;box-sizing: inherit; color: #007fac; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 13px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;Protocol-Flow&lt;/a&gt;&lt;span style=&quot;color: #555d66; font-family: &amp;quot;noto serif&amp;quot;; font-size: 13px; white-space: pre-wrap;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://creativecommons.org/licenses/by-sa/4.0/legalcode&quot; rel=&quot;noreferrer noopener&quot; style=&quot;box-sizing: inherit; color: #007fac; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 13px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;CC BY-SA 4.0&lt;/a&gt;&lt;span style=&quot;color: #555d66; font-family: &amp;quot;noto serif&amp;quot;; font-size: 13px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; color: #191e23; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;The client or the application sends requests for authorization to access resources from the resource server.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;If the user accepts the request, the application receives permission to access the user&#39;s data as per the scope of the permission.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;The client requests an access token from the authorization server or API representing the authenticity of its own identity. These access tokens life span is very short, think of their life span in terms of hours and minutes.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;If the authorization server authenticates the application&#39;s identity, then the server generates an access token to the application.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;The application requests the resource from the resource server or API. Then it sends the access token to the server for authentication.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;If the resource server finds that the access token is valid then it serves the resource to the application.&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
You need to register your application before using OAuth2 with it. It can be done by visiting the service&#39;s website&#39;s developer portion. The following details are required in order to do this.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Application Name&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Application Website&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Callback or redirect URL&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
What is Redirect URL in OAuth2&lt;/h4&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
Redirect URL means where the service will redirect users after they authorize or deny your application. It also points to the route where you will write codes to handle access tokens.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
What is Client Id in OAuth2&lt;/h4&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
After registering the application, the service issues client credentials in the form of client id that is nothing but a unique string to identify the application and it is used by the service itself. Also, it helps to create an authorization URL that is displayed to the users.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
What is Client Secret in OAuth2&lt;/h4&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
The client secret&#39;s role is to authenticate the identity of the application to the service API when the application requests to access a user&#39;s account. The value of the client secret must be kept as a secret and should not be disclosed to anyone.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative;&quot;&gt;
What is Refresh Token in OAuth2&lt;/h4&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
We already discussed that the access token has a very short life-span. When the access token expires then refresh token enables the client to reauthorize without asking the resource owner to reauthenticate.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
Alright, we discussed basics about what OAuth actually is, why we need it and what is the internal working principle behind OAuth2. Let&#39;s get down to building a node js application having facebook login built inside it that uses OAuth protocol. &lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
Creating OAuth2 Facebook Application&lt;/h2&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
At first, we need to create a facebook application, to do so visit the &lt;a href=&quot;https://developers.facebook.com/&quot; style=&quot;box-sizing: inherit; color: #007fac; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out;&quot;&gt;facebook developers page&lt;/a&gt;. Then log in with your Facebook account, this step is necessary because after doing this you will be able to get an application id and application secret that is mandatory for connecting our node js application with Facebook. &lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
1) After login click on the &quot;Get Started&quot; button, then you will something similar as shown in the screenshot below.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWV9c6dgZHxH9cjGviuimx8xPyTZawQDO91iE1LZ8sxIFYBaQfvvTRom1XpnyTYBf-CnLBx__Lfjeok3R6vcM9HKr3BVUakbkm6w3IZbeEAc9StcVVEusG8U8-yXT46uJtBzeIHCaPihP7/s1600/oauth2-facebook-signup-page.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Signup Page&quot; border=&quot;0&quot; data-original-height=&quot;460&quot; data-original-width=&quot;746&quot; height=&quot;394&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWV9c6dgZHxH9cjGviuimx8xPyTZawQDO91iE1LZ8sxIFYBaQfvvTRom1XpnyTYBf-CnLBx__Lfjeok3R6vcM9HKr3BVUakbkm6w3IZbeEAc9StcVVEusG8U8-yXT46uJtBzeIHCaPihP7/s640/oauth2-facebook-signup-page.png&quot; title=&quot;OAuth2 Facebook Signup Page&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
2) Click on the &quot;Next&quot; button, then you need to choose your job role. Choose &quot;Developer&quot; (recommended).&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4NR9aod0fxMFiq5mgxBBPyXTMgCzsUdQJb-GqDobOsLBJu5L1kHDONNUE_vVMgNQfnorgxdf6Ow3K32eJYdnroj2zzTQv2FrfuTUvm43J-A-489HsXhpMl-FrCcb-CiIpvMmKWAwO6F7g/s1600/oauth2-facebook-your-job-role.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Your Job Role&quot; border=&quot;0&quot; data-original-height=&quot;444&quot; data-original-width=&quot;745&quot; height=&quot;381&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4NR9aod0fxMFiq5mgxBBPyXTMgCzsUdQJb-GqDobOsLBJu5L1kHDONNUE_vVMgNQfnorgxdf6Ow3K32eJYdnroj2zzTQv2FrfuTUvm43J-A-489HsXhpMl-FrCcb-CiIpvMmKWAwO6F7g/s640/oauth2-facebook-your-job-role.png&quot; title=&quot;OAuth2 Facebook Your Job Role&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
3) You need to create an app first, the screen-shot for this step is shown below. &lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrnvlIhOFNVP-SMZHsQz8cT6Q0ULtLpSz7v7AU32S3ISLcNnztXThZUKc3v7qekIFfQiMwUiA7eReE5cFiHxhTxMQteZTiYwXIQEk5OujLYY0GC9-4J2QwH8J-C0D_4htg1Los1OKgFSAR/s1600/oauth2-facebook-create-app-id.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Create App Id&quot; border=&quot;0&quot; data-original-height=&quot;340&quot; data-original-width=&quot;720&quot; height=&quot;302&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrnvlIhOFNVP-SMZHsQz8cT6Q0ULtLpSz7v7AU32S3ISLcNnztXThZUKc3v7qekIFfQiMwUiA7eReE5cFiHxhTxMQteZTiYwXIQEk5OujLYY0GC9-4J2QwH8J-C0D_4htg1Los1OKgFSAR/s640/oauth2-facebook-create-app-id.jpg&quot; title=&quot;OAuth2 Facebook Create App Id&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
4) Click on &quot;I am not a robot&quot; option checkbox.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjybFy1MWHZTaoGShhoRw_BI2FBFMnThWA0uvL02ADdHds3MB8lOkXsn5pzytffg-U8FBWU2SQ9-m2YMM_eBT69Wp0zopN_FoMxBcDQNZvRyLAsdsvCt3-jwcfEcVzQ-qwjCRCcQhKmqrZg/s1600/oauth2-facebook-security-check.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Security Check&quot; border=&quot;0&quot; data-original-height=&quot;282&quot; data-original-width=&quot;560&quot; height=&quot;322&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjybFy1MWHZTaoGShhoRw_BI2FBFMnThWA0uvL02ADdHds3MB8lOkXsn5pzytffg-U8FBWU2SQ9-m2YMM_eBT69Wp0zopN_FoMxBcDQNZvRyLAsdsvCt3-jwcfEcVzQ-qwjCRCcQhKmqrZg/s640/oauth2-facebook-security-check.png&quot; title=&quot;OAuth2 Facebook Security Check&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
5) After this step, you will be redirected to the &quot;Add Product&quot; page. On that page, click on the &quot;Setup&quot; button.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ7vpmqTWHlUoQPFtyuqs7bsUmv-5NW425Zs5cHBuE_1i4m0xQB9ksljCNvV6WZtEjSTT6-v935Ft_MIdZAn9W2FAJT5vEAyXjxqlzQSwSiR5jLD1vIlVcliJyUHGO6GkipWOAkE8RhBNT/s1600/oauth2-facebook-add-product.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Add Product&quot; border=&quot;0&quot; data-original-height=&quot;415&quot; data-original-width=&quot;1341&quot; height=&quot;198&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ7vpmqTWHlUoQPFtyuqs7bsUmv-5NW425Zs5cHBuE_1i4m0xQB9ksljCNvV6WZtEjSTT6-v935Ft_MIdZAn9W2FAJT5vEAyXjxqlzQSwSiR5jLD1vIlVcliJyUHGO6GkipWOAkE8RhBNT/s640/oauth2-facebook-add-product.jpg&quot; title=&quot;OAuth2 Facebook Add Product&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
6) Then you need to choose the platform for which you want to add facebook login functionality. Select &quot;www&quot; option.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHaA78JxgFVfdjc9llftaBLqe0bETm0TDG-up8jybb1rc1BkW7eNwZZk5AcrIDRNNsDwCnoGGZilBvm1M6-EYxnkE5nrLAAc6igo2ulaFQj6rcKWNnrvMYXDWs4fbzvXaS_VtmLtX65A2g/s1600/oauth2-facebook-choose-platform.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Choose Platform&quot; border=&quot;0&quot; data-original-height=&quot;282&quot; data-original-width=&quot;957&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHaA78JxgFVfdjc9llftaBLqe0bETm0TDG-up8jybb1rc1BkW7eNwZZk5AcrIDRNNsDwCnoGGZilBvm1M6-EYxnkE5nrLAAc6igo2ulaFQj6rcKWNnrvMYXDWs4fbzvXaS_VtmLtX65A2g/s640/oauth2-facebook-choose-platform.png&quot; title=&quot;OAuth2 Facebook Choose Platform&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
7) Then you need to enter the URL of your website. If you do not have a site in production, you can definitely use &quot;localhost&quot;. I used &quot;http://localhost:8000&quot; for my this application. Click the &quot;Save&quot; button.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhawclyhlxjEjZn8EXe8AIx1GKbW3A5bFdScxU5y18Juj8iEvsQa3rW8ZBm-V9xzvsvGXep2IhS785x64p0gcbzfHNlwAiApqVb-32NnWUgzznNJmSii3zRMMV7JkfK_A9PDaaUk8etSCi6/s1600/oauth2-facebook-website-url.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Website URL&quot; border=&quot;0&quot; data-original-height=&quot;428&quot; data-original-width=&quot;956&quot; height=&quot;284&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhawclyhlxjEjZn8EXe8AIx1GKbW3A5bFdScxU5y18Juj8iEvsQa3rW8ZBm-V9xzvsvGXep2IhS785x64p0gcbzfHNlwAiApqVb-32NnWUgzznNJmSii3zRMMV7JkfK_A9PDaaUk8etSCi6/s640/oauth2-facebook-website-url.png&quot; title=&quot;OAuth2 Facebook Website URL&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
8) Then skip the rest of the steps, click the &quot;Settings&quot; option in the left-hand menu.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; color: #191e23; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcJ8usw4cn7CEtyzj2kEyU9IQbUA3mi_wydQ230qNypCzg52EPHo7HjqxNCzV7FKknKiCrZRjboJRJgl9zYqkje4fvo3Q2R-xPpr3D-zabu8mC9-L-pVF4jUEBLbBsCeZAOBXdlNGxT52d/s1600/oauth2-facebook-settings-menu.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Settings Menu&quot; border=&quot;0&quot; data-original-height=&quot;397&quot; data-original-width=&quot;226&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcJ8usw4cn7CEtyzj2kEyU9IQbUA3mi_wydQ230qNypCzg52EPHo7HjqxNCzV7FKknKiCrZRjboJRJgl9zYqkje4fvo3Q2R-xPpr3D-zabu8mC9-L-pVF4jUEBLbBsCeZAOBXdlNGxT52d/s320/oauth2-facebook-settings-menu.png&quot; title=&quot;OAuth2 Facebook Settings Menu&quot; width=&quot;182&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23;&quot;&gt;9) In the Settings page, you need to add redirect URL in order to tell facebook where a user will be redirected back after authorization. Here, again I am using localhost for doing this. I have added &quot;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://localhost:8000/auth/facebook/callback&lt;/span&gt;&lt;span style=&quot;color: #191e23;&quot;&gt;&quot; as the redirect URL. Click on the &quot;Save&quot; Changes button. &lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivGpGk5g0XmQl3LYxACPAGRBHNiOFbY_QEOcDCotGHsvCioTc78oaJANGimH5IaQy5NF9gwWuE_S9dJkTjEc0vMMPAWvBBnuJqTHpWWrDAlSbCi2VPDE592spMt69qvqP1TSc2q8K2aWZG/s1600/oauth2-facebook-oauth-settings.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Settings&quot; border=&quot;0&quot; data-original-height=&quot;504&quot; data-original-width=&quot;970&quot; height=&quot;332&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivGpGk5g0XmQl3LYxACPAGRBHNiOFbY_QEOcDCotGHsvCioTc78oaJANGimH5IaQy5NF9gwWuE_S9dJkTjEc0vMMPAWvBBnuJqTHpWWrDAlSbCi2VPDE592spMt69qvqP1TSc2q8K2aWZG/s640/oauth2-facebook-oauth-settings.png&quot; title=&quot;OAuth2 Facebook Settings&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
10) Then go to the main settings link in the top-left position. That is highlighted in the screen-shot shown below.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUDjNlDVjJyFW_ayu1cGBIPm6ApFC9Wk2PwOnMiQ_5gg4eAuP8R4EgQ88kSX6eJrsTC2W5HPVF9ZLxOB7XTiuiHjH16no_kfGb331Qg6LFGIpiku55-xkyyBjaLxpKBuBjl9NRzpXQo4aT/s1600/oauth2-facebooktop-settings.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Top Settings&quot; border=&quot;0&quot; data-original-height=&quot;397&quot; data-original-width=&quot;226&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUDjNlDVjJyFW_ayu1cGBIPm6ApFC9Wk2PwOnMiQ_5gg4eAuP8R4EgQ88kSX6eJrsTC2W5HPVF9ZLxOB7XTiuiHjH16no_kfGb331Qg6LFGIpiku55-xkyyBjaLxpKBuBjl9NRzpXQo4aT/s320/oauth2-facebooktop-settings.png&quot; title=&quot;OAuth2 Facebook Top Settings&quot; width=&quot;182&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23;&quot;&gt;11) You will see &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: blue;&quot;&gt;app id&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #191e23;&quot;&gt; and &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: blue;&quot;&gt;app secret&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;color: #191e23;&quot;&gt; keys, copy these and paste them somewhere. We will need them later.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJi3kCJQecK8x8F6JF_Woh23moIss7nuV_cxCyRUwA3C5F3LZKLixnHnHVsw40X8GS2jqS51hQud7fnuXE9OAbKak1pShSIgssLGM719hl84SJW0vKYUCtP3_FGjLOWeXaP6mObHVQsMkx/s1600/oauth2-facebook-credentials.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;OAuth2 Facebook Credentials&quot; border=&quot;0&quot; data-original-height=&quot;112&quot; data-original-width=&quot;957&quot; height=&quot;73&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJi3kCJQecK8x8F6JF_Woh23moIss7nuV_cxCyRUwA3C5F3LZKLixnHnHVsw40X8GS2jqS51hQud7fnuXE9OAbKak1pShSIgssLGM719hl84SJW0vKYUCtP3_FGjLOWeXaP6mObHVQsMkx/s640/oauth2-facebook-credentials.jpg&quot; title=&quot;OAuth2 Facebook Credentials&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
That&#39;s it, you have successfully created a facebook application which is the first step for integrating facebook login to the node js application that we will create.&lt;/div&gt;
&lt;div style=&quot;color: #191e23;&quot;&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
Conclusion&lt;/h2&gt;
&lt;div&gt;
I hope now you have a clear understanding of how oauth2 can be used to provide facebook login to a node js application. If you find this article helpful, consider sharing it with others. Thank you.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/10/oauth2-facebook-login-part-one.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR__ifG7ukjIVTaNVUplsW_dxXQkNILx05AQrI1IBxu3BzsvCVwT2wlRFqYQ3YEWwr15f5hlXBWq0OknB7oOlgE76-FgCjHlkmS8xXx0rJNJ8yrjhYDBFkIG-Vg0yS9zsEP-DYKhaokZko/s72-c/oauth2-facebook-cover-image.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-5932296694551934305</guid><pubDate>Sat, 28 Sep 2019 16:21:00 +0000</pubDate><atom:updated>2023-03-08T16:09:49.317+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><title>Facts You Need To Know About Javascript This Object Today</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0XS1L25S2NcAZuBNOI1tJ9GO-LxRorH7v0__1JGtPY1wXG93IiBXBMD2Zl1Rtr8tTL2bSR42KIFEX5dg0eoNrD58rAq1JKzfGBZxn-e2rK89MuCBtdumy99qqTORdl6obt0vnzBGf1VOB/s1600/javascript-this-object-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript this object Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;426&quot; data-original-width=&quot;640&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0XS1L25S2NcAZuBNOI1tJ9GO-LxRorH7v0__1JGtPY1wXG93IiBXBMD2Zl1Rtr8tTL2bSR42KIFEX5dg0eoNrD58rAq1JKzfGBZxn-e2rK89MuCBtdumy99qqTORdl6obt0vnzBGf1VOB/s640/javascript-this-object-cover-image.jpg&quot; title=&quot;Javascript this object Cover Image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;All of us know that javascript supports object-oriented programming features. So we can say that an object is a basic building block of OOP ( object-oriented programming). There is one special object available in &lt;b&gt;javascript, &quot;this&quot; object&lt;/b&gt;. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In this article, we will learn how &quot;this&quot; keyword actually works, how the value of &quot;this&quot; object is helpful in different situations.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But, before diving more deeply about &quot;this&quot; object, we need to know the fundamentals of how the browser executes js code.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
 Understanding Execution Context&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As we all know, javascript is a scripting language. So, naturally, the interpreter interprets javascript code. Then that the code gets executed line by line. The scope in which the code is executed is known as the execution context.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s understand this concept with an example in real-life scenarios. Suppose you were asked about your role in the project in which you are currently working. Then in response to this question, you will briefly explain your role. So, you gave your answer in the context for which the question was asked. A similar concept is applicable in javascript&#39;s execution context.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When any code is executed in javascript, it is evaluated as one of the following.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Global context: In this environment, your code is run for the first time.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Function context: It is applicable whenever the flow of execution enters a function body.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Internal context: Text that will be executed inside the internal eval function falls under this scope.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYYk5Y9hRMEgl4_whyphenhyphen7bezkXH9bCnuERC95wGHqor2xIjWA19KZ1TCEkSgM_6kTMpx67995IwRzwKpiBB3nyY85_aZFY5E3WA4_3kHebc-VtwvB1bTjfFHf00bo6CSWRSLY8lNWD6P3dEf/s1600/javascript-this-execution-context.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript this execution context&quot; border=&quot;0&quot; data-original-height=&quot;362&quot; data-original-width=&quot;972&quot; height=&quot;238&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYYk5Y9hRMEgl4_whyphenhyphen7bezkXH9bCnuERC95wGHqor2xIjWA19KZ1TCEkSgM_6kTMpx67995IwRzwKpiBB3nyY85_aZFY5E3WA4_3kHebc-VtwvB1bTjfFHf00bo6CSWRSLY8lNWD6P3dEf/s640/javascript-this-execution-context.png&quot; title=&quot;Javascript this execution context&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above screenshot, the red border indicates global context, green one refers to a function or local context. Global context can be accessed from any other context in the javascript code. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When a function is called it creates a private scope, in which anything declared inside of the function can not be directly accessed from outside the current function scope. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But, a function can easily access a variable that is declared outside of its current context. This is the fundamental concept of the execution context. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Role of Javascript this Object in Execution Context&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Now, you have a clear concept on execution context, let&#39;s discuss how &quot;this&quot; object plays its role in it.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We already know that javascript is executed as a single thread, that means only one statement will run in the browser. Other actions will be stored in a &lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Stack_(abstract_data_type)&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;stack&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; which is known as the execution context.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The execution context is changed depending on the item that is present at the top of this stack. The object that &quot;this&quot;  refers to changes every time when the execution context is changed.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot;this&quot; object refers to the global object. Whenever a code is run as part of a function call, then &quot;this&quot; refers to the global object. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For example, when we run javascript in the browser, the window object is considered a global object. In Node Js environment, a unique object &quot;global&quot; will be the value of &quot;this&quot;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5fU2eSqMxKT_oWFYwbhyphenhyphenkj0DP0sKERoUhmfoDCfWMTOX6LzRGxHm5gm62Hk3MmmTa3uM_3y8fAQoUR79l9vmytMK-8rngt7R6i3hpLr5Lr_ejUcXZvezswV7Vb72KbMTTHKSdawIXxl-m/s1600/javascript-this-global-object.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript this global object&quot; border=&quot;0&quot; data-original-height=&quot;238&quot; data-original-width=&quot;1085&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5fU2eSqMxKT_oWFYwbhyphenhyphenkj0DP0sKERoUhmfoDCfWMTOX6LzRGxHm5gm62Hk3MmmTa3uM_3y8fAQoUR79l9vmytMK-8rngt7R6i3hpLr5Lr_ejUcXZvezswV7Vb72KbMTTHKSdawIXxl-m/s640/javascript-this-global-object.png&quot; title=&quot;javascript this global object&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What Does this in Javascript Mean&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The keyword has different meanings and these depend on exactly where &quot;this&quot; keyword is used.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;It refers to the global object that is global if is called in a Node Js environment and it belongs to the window object if it is executed in the browser environment.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;At the time when a function is executed as a property of an object, then &quot;this&quot; refers to the parent object.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;When a function is called with the &quot;new&quot; operator, then &quot;this&quot; refers to the newly created instance.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;When a function is executed with apply and call method then at that time &quot;this&quot; refers to the value passed as the first parameter of apply or call method.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s discuss these use cases one by one.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Javascript this Object Use Cases&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
In IIFE(Immediately Invoked Function Expression) : &lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjycgxOeprtX3swM1hlnBVt-uppx8B2AL8t1KReTDFMUig5s8bHp-mLec35E2buMrgU3gRd91vjEFjfMhttFrFsVDYEqv6b-d876lBv93Wtj5fxaYkyfuWcm0KLOoOXZLJ_nDTueO3gPor7/s1600/javascript-this-iife.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript this object IIFE&quot; border=&quot;0&quot; data-original-height=&quot;183&quot; data-original-width=&quot;1058&quot; height=&quot;110&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjycgxOeprtX3swM1hlnBVt-uppx8B2AL8t1KReTDFMUig5s8bHp-mLec35E2buMrgU3gRd91vjEFjfMhttFrFsVDYEqv6b-d876lBv93Wtj5fxaYkyfuWcm0KLOoOXZLJ_nDTueO3gPor7/s640/javascript-this-iife.png&quot; title=&quot;Javascript this object IIFE&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If you don&#39;t know what is IIFE, you can know more about it &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/09/javascript-callback-in-depth.html&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. If &quot;use strict&quot; option is turned on, then the value of &quot;this&quot; will be undefined. Also, the global object refers to undefined in case of the window object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Refers To a Current Instance&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When we define a class in javascript, and if we define a constructor there, then that constructor will return a new instance of that class. For that scenario, &quot;this&quot; keyword will refer to the current instance of the newly created class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiF34XIL_0emqDUYUKQ8bsFR5RyPxa3DHf8oDIZQeKz0Av_a2xPY7EJM3Q_KaHYEZC82CfFKYjyegvdFIvAiabrZRCUjjfdcMRMSwWDbR5ltFrHYsoPPJSdmORk76rsSEkkbgfDYa8jCSS/s1600/javascript-this-constructor.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript this object constructor&quot; border=&quot;0&quot; data-original-height=&quot;306&quot; data-original-width=&quot;1060&quot; height=&quot;184&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiF34XIL_0emqDUYUKQ8bsFR5RyPxa3DHf8oDIZQeKz0Av_a2xPY7EJM3Q_KaHYEZC82CfFKYjyegvdFIvAiabrZRCUjjfdcMRMSwWDbR5ltFrHYsoPPJSdmORk76rsSEkkbgfDYa8jCSS/s640/javascript-this-constructor.png&quot; title=&quot;Javascript this object constructor&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Refers To Parent Object&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In javascript, the property of an object can be a value or a simple method. At the time when the method that belongs to an object is called then &quot;this&quot; refers to the object that contains the method which will be executed.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRd_z_KiLad_BV3F1sXJjpPNRwj4UYrstcDuXcdr-7qYvKfd7hmqm_aehSLG4uRv8xWQIoFJTYFNWiSZqvafT1fYqf0ya-QIv2IRwNN2MlGL7kFWcUoWhqR6ui2GZjpb5nnyLYMZyS6nBd/s1600/javascript-this-parent-object.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript this parent object&quot; border=&quot;0&quot; data-original-height=&quot;345&quot; data-original-width=&quot;1047&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRd_z_KiLad_BV3F1sXJjpPNRwj4UYrstcDuXcdr-7qYvKfd7hmqm_aehSLG4uRv8xWQIoFJTYFNWiSZqvafT1fYqf0ya-QIv2IRwNN2MlGL7kFWcUoWhqR6ui2GZjpb5nnyLYMZyS6nBd/s640/javascript-this-parent-object.png&quot; title=&quot;Javascript this parent object&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, when &lt;b&gt;user.showMessge()&lt;/b&gt; method of user instance is called, &quot;this&quot; keyword refers to the user object instead of the global object. That&#39;s why it displayed &quot;false&quot; as output. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; But, when only &lt;b&gt;showMessage()&lt;/b&gt; method is called, &quot;this&quot; keyword refers to the global object. So, that time &quot;true&quot; is displayed. At the time when &lt;b&gt;fun1()&lt;/b&gt; is called, it displayed &quot;true&quot; as it was treated as a normal function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Uses With call() and apply() Methods&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Javascript function is known to have 3 unique functions, those are call(), apply() and bind() functions. With the help of these functions, we can explicitly specify what should be referenced by &quot;this&quot; keyword within the calling function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRABKDestN1gc9_TqlweQ0TlYC3T5lx71mpMF9Lp6Q3tDJWT6zCzjMY4cvyhCJ3o9Hzt4Wbqo8luVU4yzi8LOyh10Estawmohc-PiEX96_tdvJPbGUCjRx-IkaT5i0D4qyV74Fb2HaaxD4/s1600/javascript-this-call-and-apply.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript this object call and apply&quot; border=&quot;0&quot; data-original-height=&quot;322&quot; data-original-width=&quot;1107&quot; height=&quot;186&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRABKDestN1gc9_TqlweQ0TlYC3T5lx71mpMF9Lp6Q3tDJWT6zCzjMY4cvyhCJ3o9Hzt4Wbqo8luVU4yzi8LOyh10Estawmohc-PiEX96_tdvJPbGUCjRx-IkaT5i0D4qyV74Fb2HaaxD4/s640/javascript-this-call-and-apply.png&quot; title=&quot;javascript this object call and apply&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The main difference between call and apply method is that call() function expects parameters to be passed individually, where apply() function expects them to be passed as an array of parameters.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Final Words&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope that I am able to clear all your doubts regarding javascript &quot;this&quot; object. If this article proves beneficial to you, share it among others.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/09/facts-about-javascript-this-object.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0XS1L25S2NcAZuBNOI1tJ9GO-LxRorH7v0__1JGtPY1wXG93IiBXBMD2Zl1Rtr8tTL2bSR42KIFEX5dg0eoNrD58rAq1JKzfGBZxn-e2rK89MuCBtdumy99qqTORdl6obt0vnzBGf1VOB/s72-c/javascript-this-object-cover-image.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-3996172459464410861</guid><pubDate>Wed, 18 Sep 2019 18:09:00 +0000</pubDate><atom:updated>2023-03-08T16:09:51.603+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><title>Javascript Callback Functions In Depth Guide for 2019</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI8WzAuubrNrQPXHqKq6zzc261eukIb3EpFhPWobT2-h4m5APTU2R464zNoqtmg_UcA8V53y2IO_11gZAwVISZ53Z5veR9derNHLmeCK29WDzOmUIAkHAUtnvpp32k7C_FLng87_ij_xy9/s1600/javascript-callback-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-cover-image&quot; border=&quot;0&quot; data-original-height=&quot;501&quot; data-original-width=&quot;365&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI8WzAuubrNrQPXHqKq6zzc261eukIb3EpFhPWobT2-h4m5APTU2R464zNoqtmg_UcA8V53y2IO_11gZAwVISZ53Z5veR9derNHLmeCK29WDzOmUIAkHAUtnvpp32k7C_FLng87_ij_xy9/s640/javascript-callback-cover-image.jpg&quot; title=&quot;javascript-callback-cover-image&quot; width=&quot;466&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Javascript callback&lt;/b&gt; functions; another important concept you must need to understand. Otherwise, you might face a lot of struggles for becoming a successful javascript developer. But I am sure that after reading this article thoroughly you will be able to overcome any obstacles you previously had with callbacks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Before, I will talk more about callback function, but at first, you need to have some minimal level of  knowledge about functions. I mean you should know what a function is, how it actually works, what are different types of functions etc.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
A Quick Recap: Javascript Function&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is a Function?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;A function is a logical building block inside of which a set of codes are written in order to perform a specific task. Practically, functions allow writing codes in a more organized way that is also easy to debug and maintain. Functions also allow code reuse.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You define function once, and call it when you need to without writing the same codes again and again.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
The syntax for Declaring a Function&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We talked a little about what a function is. Now, let&#39;s see how to declare a function in javascript.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;1. &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;Using Function Constructor:&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; In this approach, the function is created with the help of a &quot;Function&quot; constructor. Technically, this approach is less efficient than declaring function with the function expression syntax and function declaration statement syntax.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXEEyVxRXPJuvYNm0OZIZQcY-2BSPdMtMLBtUtQSrbHzNEpE8-YTcHM_KAzkjP9lYOXqfY2ZXks_UgQprrV5xwb3VPsK_DtIHgx-M5_frVReELx5nxh8BmJW6S208X6Q53yt0j97YwPGKI/s1600/javascript-callback-function-constructor-syntax.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-function-constructor-syntax&quot; border=&quot;0&quot; data-original-height=&quot;179&quot; data-original-width=&quot;1141&quot; height=&quot;100&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXEEyVxRXPJuvYNm0OZIZQcY-2BSPdMtMLBtUtQSrbHzNEpE8-YTcHM_KAzkjP9lYOXqfY2ZXks_UgQprrV5xwb3VPsK_DtIHgx-M5_frVReELx5nxh8BmJW6S208X6Q53yt0j97YwPGKI/s640/javascript-callback-function-constructor-syntax.png&quot; title=&quot;javascript-callback-function-constructor-syntax&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;2. &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;Using Function Expression:&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Typically, this approach is the same as a variable assignment. In simple words, the function body is considered as an expression and that expression is assigned to a variable. Functions defined with this syntax can be either named or anonymous.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;A function that has no name is known as an anonymous function. An anonymous function is self invoked, which means it calls itself automatically. This behavior is also known as immediately invoked function expression(&lt;/span&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/IIFE&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;IIFE&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3tT739lH3JwnRRy3KUO3M2AYvzIERD1B8jnzkwg2zf0XW27g_DxqT7aOwi-gQvHZm-EnKIX7Gfq9AgfHmb6C0EWq0bPBKe-Nk_1YfEfAAYC3-T8y8BHN0jud2JHNZqIYQoBwCeRT0pPAw/s1600/javascript-callback-function-expression-named-syntax.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-function-expression-named-syntax&quot; border=&quot;0&quot; data-original-height=&quot;151&quot; data-original-width=&quot;924&quot; height=&quot;104&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3tT739lH3JwnRRy3KUO3M2AYvzIERD1B8jnzkwg2zf0XW27g_DxqT7aOwi-gQvHZm-EnKIX7Gfq9AgfHmb6C0EWq0bPBKe-Nk_1YfEfAAYC3-T8y8BHN0jud2JHNZqIYQoBwCeRT0pPAw/s640/javascript-callback-function-expression-named-syntax.png&quot; title=&quot;javascript-callback-function-expression-named-syntax&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHHiX1JgCLmiagdMvYRnMA0Bxllx5s_Vmj77GXn7TdrJog7qPeoD5bVy7xqoZLQd4mxbpJl1YUtHO__-nxRKATj1FbdTSlXT-m7Vf49G6sn7rUO3APvoMGkNhku9Ntf3FQVSxbYJZncXdE/s1600/javascript-callback-function-expression-anonymous-syntax.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-function-expression-anonymous-syntax&quot; border=&quot;0&quot; data-original-height=&quot;149&quot; data-original-width=&quot;1021&quot; height=&quot;92&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHHiX1JgCLmiagdMvYRnMA0Bxllx5s_Vmj77GXn7TdrJog7qPeoD5bVy7xqoZLQd4mxbpJl1YUtHO__-nxRKATj1FbdTSlXT-m7Vf49G6sn7rUO3APvoMGkNhku9Ntf3FQVSxbYJZncXdE/s640/javascript-callback-function-expression-anonymous-syntax.png&quot; title=&quot;javascript-callback-function-expression-anonymous-syntax&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;3. &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;Using Function Declaration Statement:&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Actually, this method is the old school method that is used commonly in javascript. Here, after the keyword &quot;function&quot; you have to specify the name of the function. After that, if the function accepts multiple parameters or arguments; you need to mention them too. Although this part is completely optional. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the body of the function, the function must return a value to the caller. After a return statement is found, the function will stop executing. Inside the function, the parameters will act as a local variable.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Also, the variables that are declared inside the function will be local to that function. Local variables can be accessed within that function only, so variables with the same name can easily be used in different functions. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDd6dF4n_F7r4RPU0weMz3y5Si6fSiAzsMCEbB-wVU3er_Z-7iQm4TEmQTGcNngL3GxQ1nhCzgrb2dmZ-mSYBKT0QPAlBeCz4LWpMfAqCgebiKrxLsS5MjVeH3NbILnprq0dzNAI1EkR91/s1600/javascript-callback-function-declaration-syntax.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-function-declaration-syntax&quot; border=&quot;0&quot; data-original-height=&quot;167&quot; data-original-width=&quot;962&quot; height=&quot;110&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDd6dF4n_F7r4RPU0weMz3y5Si6fSiAzsMCEbB-wVU3er_Z-7iQm4TEmQTGcNngL3GxQ1nhCzgrb2dmZ-mSYBKT0QPAlBeCz4LWpMfAqCgebiKrxLsS5MjVeH3NbILnprq0dzNAI1EkR91/s640/javascript-callback-function-declaration-syntax.png&quot; title=&quot;javascript-callback-function-declaration-syntax&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Invoking a Function&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The function declared before will be invoked when any one of the following occurs:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;When an event occurs, for example, the user clicks on a button or the user selects some option from the dropdown list, etc.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;When the function is called from the javascript code.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;The function can also be invoked automatically, we already discussed that in anonymous function expression.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The () operator invokes the function.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Javascript Callback Function?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per MDN:  &lt;i&gt;A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action&lt;/i&gt;. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I know after reading this technical definition, you are confused and hardly able to understand what is actually a callback function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let me clarify this with simple words, a callback function is a function that will be executed just after another function has finished executing. The callback function is a function that is passed as an argument to another javascript function. That callback function is executed inside of the function it was passed into.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In javascript, functions are treated as first-class objects. By saying the first-class object, we mean that a number or a function or a variable can be treated as same as any other entity in the language. Being a first-class object, we can pass functions to other functions as variables and functions can be returned from other functions too.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Functions that can do this are known as higher-order functions. A callback function is actually a pattern. The word &quot;pattern&quot;  means some sort of proven methodology to solve a common problem in software development. There it is better to call the use of callback function as a callback pattern.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Why We Need Javascript Callback?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The client-side javascript runs in the browser and the main browser process is a single-threaded &lt;/span&gt;&lt;a href=&quot;https://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;event loop&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. If we try to execute long-running operations within a single-threaded event loop, the process is blocked. This is technically bad because the process stops processing other events while waiting for your operation to complete.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For example, the &quot;alert&quot; statement is considered as one of the blocking codes in javascript in the browser. If you run alert; you can no longer do any interaction within the browser, until you close the alert dialog window. In order to prevent blocking on long-running operations, a callback is used. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s dive deep so that you will understand exactly which scenario callback is used.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8oAF6BLFbu-B0F45i8bXiPdDIH1R48db42tbl1i_4ivb4vOlvViHKF8Xh-t2TXidIa8JGb0mpHCHcd5EjdKN7OGvsVJa_P_PBD85CbeTn2l6X-GnhQJdjH9KRRHj7GEoe8BONa3RWNb2b/s1600/javascript-callback-function-usage-scenario.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-function-usage-scenario&quot; border=&quot;0&quot; data-original-height=&quot;249&quot; data-original-width=&quot;1138&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8oAF6BLFbu-B0F45i8bXiPdDIH1R48db42tbl1i_4ivb4vOlvViHKF8Xh-t2TXidIa8JGb0mpHCHcd5EjdKN7OGvsVJa_P_PBD85CbeTn2l6X-GnhQJdjH9KRRHj7GEoe8BONa3RWNb2b/s640/javascript-callback-function-usage-scenario.png&quot; title=&quot;javascript-callback-function-usage-scenario&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, getMessage() function is executed at first and then displayMessage() is executed. Both displayed a message in the browser&#39;s console window and both of them executed immediately.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But in certain situations, some codes are not executed immediately. For example, if we assume that getMessage() function performs an API call where we have to send the request to a server and wait for the response, then how we will be able to deal with it ?&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;Simple, to handle that kind of scenario, we need to use callback functions in javascript.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
How To Use Javascript Callback Function?&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Rather than telling you about the syntax of javascript callback functions, I think it would be better if we try to implement a callback function on our previous example. The code snippet is shown below in the following screenshot.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPlESHuqerrJ-egZLqqtWAgGZXeQK_htvr46CZJfvG_pncqtlBHG3bSQWlJ4fkla7vvaS_IuTZmnI7MPiW-6V7LhY9Jz8Ofqq5NE9JXpdGYIGuoxBtHfroBYmK5M_iJhhdaZU7E4nMGk1m/s1600/javascript-callback-function-how-to.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;javascript-callback-function-how-to&quot; border=&quot;0&quot; data-original-height=&quot;270&quot; data-original-width=&quot;1116&quot; height=&quot;154&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPlESHuqerrJ-egZLqqtWAgGZXeQK_htvr46CZJfvG_pncqtlBHG3bSQWlJ4fkla7vvaS_IuTZmnI7MPiW-6V7LhY9Jz8Ofqq5NE9JXpdGYIGuoxBtHfroBYmK5M_iJhhdaZU7E4nMGk1m/s640/javascript-callback-function-how-to.png&quot; title=&quot;javascript-callback-function-how-to&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In order to use a callback function, we need to perform some sort of task that will not be able to display results immediately. To emulate this behavior, we are using javascript&#39;s setTimeout() function. That function will take 2 seconds to display the message &quot;Hi, there&quot; to the console window. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After this message is displayed, then &quot;Displayed message&quot; will be shown in the console window of the browser. So in this scenario, at first we are waiting for the getMessage() function and after this function is executed successfully, we are executing displayMessage() function.&lt;/span&gt;&lt;/div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
How Javascript Callback Works?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let me explain what actually happened behind the scene in the previous example. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As you can see from the previous example, in the getMessage() function, we are passing two arguments; the first argument is the &quot;msg&quot; variable which gets displayed in the browser&#39;s console window and second argument is the &quot;callback&quot; function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Now, you may wonder why the &quot;callback&quot; function is passed as the argument. It&#39;s because to implement callback function, we must pass a function as an argument to another function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After getMessage() function finishes it&#39;s task, we are calling that &quot;callback()&quot; function. After that when we are calling getMessage() function, we passed reference to  &quot;displayMessage()&quot; function, which is treated as a callback function.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Note carefully that, when getMessage() function is called, we are only passing the reference to the &quot;displayMessage&quot; function. That&#39;s why, you will not see the function invoke operator i.e, &quot;()&quot; beside it.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Is Javascript Callback Asynchronous?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Javascript is considered as a single-threaded scripting language. By the term &quot;single threaded&quot; it means that javascript execute one code block at a time. When javascript is busy executing one block, it is not possible for it to move to the next block.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In other words, we can say that the javascript code is always blocking in nature. But this blocking nature prevents us to write code in certain situations when we are not able to get the immediate results after running some specific tasks.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I am talking about tasks such as the following. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Sending API call to certain endpoints for getting data.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Sending network requests to get some resources (for example, text file, image file, binary file, etc. ) from a remote server.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To handle these situations, we must write asynchronous codes and the callback function is one approach to deal with these situations. So, callback functions are asynchronous in nature.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Javascript Callback Hell?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Callback hell occurs when multiple asynchronous functions are executed one after another.  It is also known as the pyramid of doom.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Let&#39;s assume, you want to get list of all Github users, then among the users, you want to search for only top contributors for javascript repository. Then among the persons, you want to get details of the person whose name is Jhon.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To implement this functionality with the help of callbacks, the code snippet will be similar as shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/e4aa30669cddc6d786f91b26dab5bbfb.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;From the above code snippet, you can see that the code becomes harder to understand, harder to maintain and also harder to modify. This happens due to the nesting of all the callback functions.&lt;/span&gt;&lt;/div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
How do you stop Callback Hell?&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Multiple techniques can be used to avoid callback hell there are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;By using &lt;a href=&quot;https://www.devhelperworld.in/2019/09/javascript-promises-definitive-guide.html&quot; target=&quot;_blank&quot;&gt;promises&lt;/a&gt;.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;With the help of async-await&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;By using async.js library&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I have already discussed, how to work with promises and how async-await can be helpful to avoid callback hell.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
By Using Async.js Library&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s talk about working with the async.js library in order to avoid callback hell.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;As per the official website of async.js :  &lt;i&gt;Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript&lt;/i&gt;. &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;Async.js provides near about 70 functions in total. For now, we will discuss only two of them i.e, async.waterfall() and async.series().&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
async.waterfall()&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;It is useful when you want to run some tasks one after the other and then pass the result from the previous task to the next task. It takes an array of functions &quot;tasks&quot; and a final &quot;callback&quot; function that is called after all functions in &quot;tasks&quot; array have completed or a &quot;callback&quot; is called with an error object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/8f0db69ea47ebcbb9c150e60cc198522.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
async.series()&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This function is helpful when you want to run functions and then you need to get the results after all the functions have executed successfully. Main difference between async.waterfall() and async.series() is that async.series() dont pass the data from one function to another function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/0185a95d4cbea4e105aaf22791a63c9a.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Javascript Callback vs Closure&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Closure&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In technical terms, closure is the combination of a function that is bundled together having references to its surrounding state.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Simply saying, a closure allows access to the outer function&#39;s scope from an inner function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To use a closure, we need to define a function inside another function. Then we need to return it or pass it to another function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Callback&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Conceptually callbacks are similar to closure. A callback is basically where a function accepts another function as an argument. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Final Words&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope this article clears all your doubts on javascript callback functions. If you find this article helpful, share it among others.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/09/javascript-callback-in-depth.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI8WzAuubrNrQPXHqKq6zzc261eukIb3EpFhPWobT2-h4m5APTU2R464zNoqtmg_UcA8V53y2IO_11gZAwVISZ53Z5veR9derNHLmeCK29WDzOmUIAkHAUtnvpp32k7C_FLng87_ij_xy9/s72-c/javascript-callback-cover-image.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-7547945331081709248</guid><pubDate>Sat, 14 Sep 2019 14:26:00 +0000</pubDate><atom:updated>2023-03-08T16:09:59.826+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Javascript</category><title>Promises In Javascript A Complete Guide for 2019</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkmj_yU0m2J3dsAkl7u4UWQhMjvdH_pYzf7sN3zKXJGXhwM2OclkShnG1a7UL1ExA_bd07N9Rw8478s8zrc2V6-N7cLp0fLG_rF-JWxluGNrpG_z8gwMqii5fCE-zkxuPGC2RutN0Y1diX/s1600/promises-in-javascript-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Promises in Javascript Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;1600&quot; data-original-width=&quot;1067&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkmj_yU0m2J3dsAkl7u4UWQhMjvdH_pYzf7sN3zKXJGXhwM2OclkShnG1a7UL1ExA_bd07N9Rw8478s8zrc2V6-N7cLp0fLG_rF-JWxluGNrpG_z8gwMqii5fCE-zkxuPGC2RutN0Y1diX/s640/promises-in-javascript-cover-image.jpg&quot; title=&quot;Promises in Javascript Cover Image&quot; width=&quot;426&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Promises in javascript&lt;/b&gt; is an important concept that is essential for a javascript developer to understand. If this concept is clear, the developer can utilize this in a variety of ways in their day-to-day lives. &lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;There are a lot of articles, tutorials available on the web about promises. But, very few of them act as a comprehensive guide to make use of promises. In this article, I will try to elaborate on promises in-depth. So you won&#39;t need to go through other resources.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is a promise?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per MDN documentation:  &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;A promise is an object that represents the eventual completion or failure of an asynchronous operation, and it&#39;s resulting value.&lt;/span&gt;&lt;/em&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Why Do We Use Promises In JavaScript?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Generally speaking, javascript is a scripting language that is synchronous in nature. In order to perform asynchronous operations, promises are of great help. Before promises were invented, when dealing with multiple asynchronous tasks, &lt;a href=&quot;https://www.devhelperworld.in/2019/09/javascript-callback-in-depth.html&quot; target=&quot;_blank&quot;&gt;callbacks&lt;/a&gt; were used a lot.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But multiple callback functions lead to unmanageable code that produced something known as callback hell&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. To solve this issue, promises are used.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;i&gt;That&#39;s a lot of technical jargon, right! But, I think you would understand promises better if the discussion goes in a non-technical approach.&lt;/i&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
How Do Promises in Javascript Actually Work?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You can think of javascript promises similar to promises you make in real life.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Imagine, you made a promise to your girlfriend that you will buy her an expensive gift. You don&#39;t know whether you will be able to keep your promise. Maybe you will be able to keep your promise or maybe not.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, if you promised but still didn&#39;t manage to purchase the gift, the promise is in a pending state. If you are able to keep your promise, then your promise is fulfilled. But, if for some reason, you are unable to do so, your promise is in the rejected state.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
When Was Promise Introduced in Javascript?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Promises&amp;nbsp;aren&#39;t a brand-new concept. In fact,&amp;nbsp;they have&amp;nbsp;been around since 1976,&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Futures_and_promises&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;when&amp;nbsp;the term was&amp;nbsp;first introduced&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. At the starting&amp;nbsp;of 2011, the concept of it was&amp;nbsp;made popular&amp;nbsp;by jQuery&amp;nbsp;deferred objects.&amp;nbsp;The concept of deferred objects are similar to promises, but they do not follow the exact technical specification as stated in the ECMA script 2015 for promises.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Finally, promises were officially added in the ECMA script 2015 specification and have also implemented in all of the latest browsers and in Node Js.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Different States In A Promise&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The same concepts apply to promises as well. A promise has any one of the following states. These are as follows:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Pending: The task relating to the promise hasn&#39;t fulfilled or rejected yet.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Fulfilled: The task relating to the promise succeeded.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Rejected: The task relating to the promise failed.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;One important point to note here is that the function that creates the promise is able to keep track of the promise states.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Getting To Know More About The Promise Object&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/4ef351aba3825bd05ca2e3d067f22694.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the code above, we created a promise, if the value of variable &quot;isPossibleToPurchaseGift&quot; is set to true then the promise is resolved. Finally, we are displaying that promise&#39;s resolved state in the browser&#39;s console window.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If we look closer in the console window, we are able to expand the Promise object, then if we expand the highlighted portion as shown in the screenshot below, we are able to get the same as shown in the screenshot below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVepwKYEcQEWgqI-7_NErmcEjGj-NqqzbfAUiOzts_XCtjUXuL-dVO89HNkLurn42RlsVa7hU00TtyPCSY-lhOAH84knzJt1Fec4FlH1rbc71tBrfWK5dfyf82ev7DP0RBHyKzHyVbkCCy/s1600/javascript-promises-object-in-depth-two.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript promise object in depth part one&quot; border=&quot;0&quot; data-original-height=&quot;287&quot; data-original-width=&quot;1338&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVepwKYEcQEWgqI-7_NErmcEjGj-NqqzbfAUiOzts_XCtjUXuL-dVO89HNkLurn42RlsVa7hU00TtyPCSY-lhOAH84knzJt1Fec4FlH1rbc71tBrfWK5dfyf82ev7DP0RBHyKzHyVbkCCy/s640/javascript-promises-object-in-depth-two.png&quot; title=&quot;Javascript promise object in depth part one&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If we expand further, we will see something similar as shown below. Note, the highlighted portions in the image.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP_cel9mG6U6QS8wGIyN0lLZAW4zbRMzdD2J-z2ILKnhfUhYSriU0Uk5ac1gdhZ4bBE-goRlwzaHWbekzYDLhlItQ02Io61HiRsCMXF81cytSlB3ZfvnYIjqhFmqBG7tjXKbqc81SMgAjz/s1600/javascript-promises-object-in-depth-three.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript promise object in depth part two&quot; border=&quot;0&quot; data-original-height=&quot;491&quot; data-original-width=&quot;1341&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjP_cel9mG6U6QS8wGIyN0lLZAW4zbRMzdD2J-z2ILKnhfUhYSriU0Uk5ac1gdhZ4bBE-goRlwzaHWbekzYDLhlItQ02Io61HiRsCMXF81cytSlB3ZfvnYIjqhFmqBG7tjXKbqc81SMgAjz/s640/javascript-promises-object-in-depth-three.png&quot; title=&quot;Javascript promise object in depth part two&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Static Methods in Promise Object&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;&lt;i&gt;Promise.all(promises):&lt;/i&gt; It waits for all promises to resolve and returns the array of all the results of the promises. An important point to note here is that, if any of the promises are not fulfilled, then that becomes the error of the Promise.all and all other results are ignored.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;&lt;i&gt;Promise.allSettled(promises)&lt;/i&gt; : It is recently added method. Its purpose is to wait for all promises to settle and return their results as an array of objects with the state ( that could be either &#39;fulfilled&#39; or &#39;rejected&#39; ) and value ( if fulfilled ) or reason (if rejected).&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;&lt;i&gt;Promise.race(promises):&lt;/i&gt; It waits for the first promise to resolve and its outcome or error becomes the result.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;&lt;i&gt;Promise.resolve(value):&lt;/i&gt; It produces a resolved promise with the given value.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;&lt;i&gt;Promise.reject(error):&lt;/i&gt; It generates a rejected promise with the given error.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating A Promise In Javascript&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/d87d9a41aafe50e53d3535c1640b28e8.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the code above, we have created a promise called &quot;willGetNewGift&quot;. The promise constructor takes two parameters, first is resolve function and the second one is reject function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Promise Resolve in Javascript?&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In simple words, resolve function indicates if the promise is succeeded then the promise object is resolved with a given value. So, in the above code snippet, if &quot; willGetNewGift&quot; variable is set to true then the promise will return a gift object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Promise Reject in Javascript?&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The reject function returns a promise object that is rejected with an error message. In, the above code snippet if &quot; willGetNewGift&quot; variable is set to false, then this promise will return an error object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Invoking The Promise In Javascript&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/a91d84240f9ac92bde6d67e8046a162e.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the code above, we are calling the promise named &quot;willGetNewGift&quot; and then in order to get the value of the fulfilled promise we are using then() function. We set the variable &quot;isPossibleToPurchaseGift &quot; to true. If the value is true we are considering that the promise is resolved. So, we are able to display the gift object inside then() function. The complete code is shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/4564471db75e6d2462fe9aef48712063.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Chaining Promises in Javascript&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Non-Technical Point of View&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s assume after making a promise to your girlfriend to buy her an expensive gift, then you would also like to attend dinner with her and finally, you would love to go on a long drive with her. Imagine, the situation here, after keeping your first promise, you will have to keep your second and third promise too.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To handle these kinds of situations you would need to chain multiple promises together. So promise chaining comes handy in these situations.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Technical Point of View&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;The promise object is capable of performing asynchronous tasks in javascript. Each asynchronous task will return a promise object and each promise object will have a then function that can take two parameters, a success handler and an error handler.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt; The then function will also return a promise, so that it is possible to chain multiple promises. &lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt; Each of the handlers (success or error) can also return a value, which will be passed to the next function as a parameter, in the chain of promises. &lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt; If a handler returns a promise, then the next handler will be called only after that request is finished. &lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s justify what we said earlier with an example.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Implementing Promise Chaining in Javascript&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/0aa0db508bec051e94879cd2f2185082.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, we defined 3 separate functions, first function &quot;willGetNewGift&quot; returns a promise object, the other functions also return promises.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let me explain exactly what happened.  At first, &quot; willGetNewGift &quot; function is called that returns a promise then that promise object is passed to the next function &quot;willAttendDinner&quot;, similarly it also returns a promise object.  Again, that object is passed to &quot;willGoOnALongDrive&quot; function. Finally, the result of the function is displayed on the console. That&#39;s why you will be able to see &quot;&lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You kept your last promise by going on a long drive!&lt;/em&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&quot; this message.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Promise.all()?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In simple words, promise.all() is a method that is beneficial when we have multiple promises and we have to wait for each individual promises to complete before the next promise can be executed.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per MDN documentation:  &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;code style=&quot;background: rgb(243, 244, 245); border-radius: 2px; box-sizing: inherit; color: #23282d; direction: ltr; font-family: Menlo, Consolas, monaco, monospace; font-size: 16px; margin: 0px 1px; padding: 2px; unicode-bidi: embed; white-space: pre-wrap;&quot;&gt;&lt;em style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;Promise.all()&lt;/span&gt;&lt;/em&gt;&lt;/code&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&amp;nbsp;method returns a single&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;&lt;code style=&quot;background: rgb(243, 244, 245); border-radius: 2px; box-sizing: inherit; color: #23282d; direction: ltr; font-family: Menlo, Consolas, monaco, monospace; font-size: inherit; margin: 0px 1px; padding: 2px; unicode-bidi: embed;&quot;&gt;&lt;em style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;Promise&lt;/span&gt;&lt;/em&gt;&lt;/code&gt;&lt;/a&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&amp;nbsp;that resolves when all of the promises passed as an iterable have resolved or when the iterable contains no promises. It rejects with the reason of the first promise that rejects. &lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&lt;span style=&quot;font-style: normal; font-weight: 400;&quot;&gt;So, one fact is clear from the documentation that, if anyone of the promise objects in the array gets rejected, the entire Promise.all() method gets rejected.&lt;/span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; font-style: normal; font-weight: 600; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;How Does Promise.all() Work?&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: italic; font-weight: 600;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;font-style: normal; font-weight: 400;&quot;&gt;From the MDN docs, we know that Promise.all() method takes an iterable object. By iterable object, it means that the object can be iterated easily. String and arrays are examples of such kind of iterable objects.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: italic; font-weight: 600;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;font-style: normal; font-weight: 400;&quot;&gt;Generally, this method returns a pending promise object that gets resolved or rejected in an asynchronous way as soon as the promise in the given iterable object has resolved or rejected. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: italic; font-weight: 600;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;font-style: normal; font-weight: 400;&quot;&gt;After promise is resolved successfully, the values of the respective promises will be there in the same order at the time they are passed in the promise all method.  If any of the promises in the iterable gets rejected, all the promises get rejected. This incident will take place even if the rest of the promises are resolved successfully.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: italic; font-weight: 600;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: italic; font-weight: 600;&quot;&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; font-style: normal; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;Implementing Promise.all() in Javascript&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/d1a864ccd70a6886a304317f371a3a80.js&quot;&gt;&lt;/script&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, we created 3 functions each of them returns a promise object. Then we called each of them in Promise.all() function, which returned the result of the promises inside an array. The output of this is shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi856-ayMCNx4RnZ0L2GQHpIHKMvkV3GiT3NT3NlJaSTbCWIRh4Y8pRjmeEfDEeaVoAIgm8qnq-gaNTgsXGhMVD0yoE061lDObC3MR10FJvSVA7JUd-1LczJTuT2iVF0l-q5gMsNra3oV90/s1600/javascript-promises-object-promise-all.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript promise all first output&quot; border=&quot;0&quot; data-original-height=&quot;287&quot; data-original-width=&quot;683&quot; height=&quot;268&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi856-ayMCNx4RnZ0L2GQHpIHKMvkV3GiT3NT3NlJaSTbCWIRh4Y8pRjmeEfDEeaVoAIgm8qnq-gaNTgsXGhMVD0yoE061lDObC3MR10FJvSVA7JUd-1LczJTuT2iVF0l-q5gMsNra3oV90/s640/javascript-promises-object-promise-all.png&quot; title=&quot;Javascript promise all first output&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If anyone of the promise fails to resolve, the result will generate an error. The code snippet is shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/1f412049b78ff576adc1139614396bd1.js&quot;&gt;&lt;/script&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
The output of the code is shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxjrFRsuJOkZx9AFeJRuv68SQf1eLE5LE8UQ5fM_iemmYuH6QPoWug80hM926H6-JOW4BMGruN8vBhq3XRmIzfFtqLLRn_SB_hZD7OblDqbLowIh1IGoqDx-kK3hkT21utmXAQe-Wf1fQb/s1600/javascript-promises-object-promise-all-output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript promise all second output&quot; border=&quot;0&quot; data-original-height=&quot;112&quot; data-original-width=&quot;550&quot; height=&quot;130&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxjrFRsuJOkZx9AFeJRuv68SQf1eLE5LE8UQ5fM_iemmYuH6QPoWug80hM926H6-JOW4BMGruN8vBhq3XRmIzfFtqLLRn_SB_hZD7OblDqbLowIh1IGoqDx-kK3hkT21utmXAQe-Wf1fQb/s640/javascript-promises-object-promise-all-output.png&quot; title=&quot;Javascript promise all second output&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Promise.race()?&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If we need to return the result of the first resolved promise or rejected promise as soon as it is available, then we should use this function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As per MDN documentation,  &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;The&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;code style=&quot;background: rgb(243, 244, 245); border-radius: 2px; box-sizing: inherit; color: #23282d; direction: ltr; font-family: Menlo, Consolas, monaco, monospace; font-size: 16px; margin: 0px 1px; padding: 2px; unicode-bidi: embed; white-space: pre-wrap;&quot;&gt;&lt;em style=&quot;box-sizing: inherit;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;Promise.race()&lt;/span&gt;&lt;/em&gt;&lt;/code&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&amp;nbsp;method returns a promise that fulfills or rejects as soon as one of the promises in an iterable fulfills or rejects, with the value or reason from that promise. &lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;box-sizing: inherit; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative;&quot;&gt;
&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;
Implementing Promise.race() in Javascript&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;
&lt;/span&gt;&lt;/em&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;
&lt;/span&gt;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/3858e96e5e7f13795597b24c8c27b8f3.js&quot;&gt;&lt;/script&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, we can see that from the 3 functions that return promise objects upon successful execution, only willGetNewGift() function took 500 milliseconds to execute. So the result of this promise is returned after running this code block.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVEN9SIaJJ59jG3uBCJj8XgRT7dOrpNBTYt-KRDaWUrOHfQlOcB9GsqdYJsI1JKABlH10cDEaHmh-mfK7OaDqsjo80wHmCAzYE6EBKW3LNbk0kpZiQkYjMotgT4f5gwvenrghkrw-DcjDs/s1600/javascript-promises-object-promise-race-output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript promise race output&quot; border=&quot;0&quot; data-original-height=&quot;90&quot; data-original-width=&quot;421&quot; height=&quot;136&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVEN9SIaJJ59jG3uBCJj8XgRT7dOrpNBTYt-KRDaWUrOHfQlOcB9GsqdYJsI1JKABlH10cDEaHmh-mfK7OaDqsjo80wHmCAzYE6EBKW3LNbk0kpZiQkYjMotgT4f5gwvenrghkrw-DcjDs/s640/javascript-promises-object-promise-race-output.png&quot; title=&quot;Javascript promise race output&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Are Javascript Promises Synchronous or Asynchronous?&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;At first, you should know that javascript is a single-threaded scripting language. Single-threaded means that it must execute one block of code before moving to execute the next code block. In simple words, the javascript code is always blocking in nature. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Sometimes we need to perform some tasks, and we are not sure exactly when that task will be complete and its result will be returned. But, at the same time, we need to guarantee that some blocks of code must be executed when we get a successful result or if a failure occurs we need to handle that scenario too.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To tackle these situations, we need to write asynchronous codes in javascript. Promises allow writing codes in an asynchronous way. So, obviously, we can say that promises are asynchronous.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s justify with an example that promises are asynchronous.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/e29aa5f05c1dda7ce5c365b74f3b5c9e.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Probably, you expected the following output.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Before giving gift&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;You kept your last promise by going on a long drive!&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;After giving gift&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;But, the actual output is shown in the screenshot below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7__6_G4ebm2LFwP8jsVA3m2nGP0n6vrC-rRyXHnEKVOER6ekyeTn9fbp4_UWXVX86Z4uBib7cDdJkzn18nwHi94AKKr17T6KkBZFQZcLLQnYlCptLcN3Ptbh1FnTJwecxXTLPBP0AiZi6/s1600/asynchronous-javascript-promises-example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Javascript promises are asynchronous&quot; border=&quot;0&quot; data-original-height=&quot;148&quot; data-original-width=&quot;450&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7__6_G4ebm2LFwP8jsVA3m2nGP0n6vrC-rRyXHnEKVOER6ekyeTn9fbp4_UWXVX86Z4uBib7cDdJkzn18nwHi94AKKr17T6KkBZFQZcLLQnYlCptLcN3Ptbh1FnTJwecxXTLPBP0AiZi6/s640/asynchronous-javascript-promises-example.png&quot; title=&quot;Javascript promises are asynchronous&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Implementing Javascript Promises in Cleaner Way&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;All the examples in this article use the syntax of promise wrapper. We used this syntax so that you can understand promises easily, but practically we can write promises in a lot of better ways. If we write promises in that approach, maintaining promises for complex tasks will be a lot easier.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let me explain what I mean by promise wrapper. In promise wrapper, you write codes that resolve or reject a promise depending on whether a promise successfully executed or not.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/ad8156f669bcd1f152c1ab2d50a5ed44.js&quot;&gt;&lt;/script&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Above code snippet is the example of a promise wrapper.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Following code snippet explains how you can write promises in a better way.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/8b5db388b8d18336dc9d7564dc0863a8.js&quot;&gt;&lt;/script&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;Try uncommenting each of the commented statements one at a time, then run the codes again. I am sure you will understand the differences pretty easily.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Writing Javascript Promises With ES6/ES2015, ES7&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;ES6 or ES2015 introduced &quot;let&quot;, &quot;const&quot; and &quot;fat arrow&quot; syntax. Using that you can write promises in a better way. We can rewrite the previous example in a better way with ES6. The code snippet is shown below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/ec22b2ac71efb259389aa0d194243bff.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You can play around the code snippet better if you uncomment the commented lines.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;ES7 introduced async and await syntax. After applying this to our ES6 code it would be easier for us to understand. Also, we don&#39;t need to use then and catch functions. For error handling you need to use try...catch syntax of javascript.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/5c0da0be62f8b2cb26e4ddfaed831480.js&quot;&gt;&lt;/script&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Again, to understand the code better I would advise you to uncomment commented codes one at a time. This way you will understand better.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Conclusion&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope after reading this article you will understand javascript promises in-depth. If you find this article helpful, don&#39;t forget to share it among others. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/09/javascript-promises-definitive-guide.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkmj_yU0m2J3dsAkl7u4UWQhMjvdH_pYzf7sN3zKXJGXhwM2OclkShnG1a7UL1ExA_bd07N9Rw8478s8zrc2V6-N7cLp0fLG_rF-JWxluGNrpG_z8gwMqii5fCE-zkxuPGC2RutN0Y1diX/s72-c/promises-in-javascript-cover-image.jpg" height="72" width="72"/><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-8838237802162564279</guid><pubDate>Sat, 24 Aug 2019 12:56:00 +0000</pubDate><atom:updated>2023-03-08T16:10:02.243+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">node.js</category><title>A Complete Guide To Passport JS Part 1</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3LD4etmpG5_GSuDOoo8PksKd08gSHaOrvl_aX1gvdxZDURZoesctlGC5OMVYO3WO1_Ahcl2GmV0-WoKFX39ZlhfAURZaI71_lgYPTznpi0Uy6pMV-RJRltbn0fQTCgkNP6-46iQNlW-Xo/s1600/passport_js.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Complete guide to passport js part 1&quot; border=&quot;0&quot; data-original-height=&quot;426&quot; data-original-width=&quot;640&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3LD4etmpG5_GSuDOoo8PksKd08gSHaOrvl_aX1gvdxZDURZoesctlGC5OMVYO3WO1_Ahcl2GmV0-WoKFX39ZlhfAURZaI71_lgYPTznpi0Uy6pMV-RJRltbn0fQTCgkNP6-46iQNlW-Xo/s640/passport_js.jpg&quot; title=&quot;Complete guide to passport js part 1&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In simple words, &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;passport js &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;is a middleware for the express js framework. It allows developers to integrate different types of authentication strategies with very little amount of code. For example: developers can add various types of sign in functionality with different services like google, facebook, twitter, github etc, also developers can add their own custom strategy by authenticating users with email and password.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We can also combine all of the strategies so that users can login with any one of the selected strategies. It is much quicker to use passport js rather than building a custom authentication strategy from scratch.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When I first started working with passport js, it took me several days to fully understand the inner-workings of it. I went through the official documentation, searched for tutorials, looked in stack overflow for help, after doing all these extra work I was able to understand it. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Topics Covered In This Article&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Setting up callback function for configuring passport strategy.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Importance of passport.authenticate() function in callback url.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Setting up middleware to check if a user is already logged in or not.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;How serializeUser() and deserializeUser() actually works.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;A sample application that will connect all these points practically that are discussed in this article.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Ok, so let&#39;s get started.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Setting up callback function for configuring passport strategy&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Take a look at the code below. Here, we have required the module for passport local strategy, we added two routes; one for displaying login page and another for handling the callback url. After &quot;/login&quot; route is called, we request users to enter their email id and password.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/346c41f5f59912f05c5ef9d000405e08.js&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; If email id and password submitted by the user matches with these values, we return the email id of the user. If no match is found then we return &lt;/span&gt;&lt;em style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;false&lt;/em&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; to indicate that authentication failed.  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This is possible with the help of done() function. It is an internal passport js function that takes care of supplying user credentials after user is authenticated successfully. This function attaches the email id to the request object &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;so that it is available on the callback url as &quot;req.user&quot;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;It will be available for the dashboard route, where you would set the session for the user and then to another part of your web application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
 Importance of passport.authenticate() function &lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This function is internally used by passport js to make sure that users are logged in before they are going to that url directly. It should be used in such a situation when they must be logged in order to access a protected url of the application. For example, to access dashboard page user must be logged in first.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
 Setting up middleware to check if a user is already logged in or not &lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To check if someone is logged in we need to check if req.session.user value is set. Then we need to use this function as &lt;/span&gt;&lt;a href=&quot;https://www.tutorialspoint.com/expressjs/expressjs_middleware.htm&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;middleware&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; on &lt;a href=&quot;https://www.devhelperworld.in/2019/07/web-programming-basics.html&quot; target=&quot;_blank&quot;&gt;GET&lt;/a&gt; route(s) that we want to grant access to only logged in users. The code for middleware is given below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/8753316ede08fa13a1eb4031f1fab348.js&quot;&gt;&lt;/script&gt; &lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code, we checked to see if the user is authenticated or not using passport js&#39;s built in isAuthenticated() function. If user is authenticated, the request continues as next() function is called. Otherwise, user is redirected to login page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We want to allow only logged in users to visit the dashboard page, the code for doing so is given below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/6a4e9060b5f7dede49716a2f74041c76.js&quot;&gt;&lt;/script&gt; &lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the code above, we have added the isLoggedIn() function that we created earlier to the dashboard route. It will act as a middleware to allow only logged in users to visit the dashboard page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
 How serializeUser() and deserializeUser() actually works &lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After successful authentication, passport attaches user&#39;s email id to the req.user object. It is possible due to the existence of serializeUser() and deserializeUser() functions.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Previously, when we configured passport js by setting up the callback function, we passed the email value in done() callback function. This step was necessary, as passport needs to take the email id and store it internally in req.session.passport object which is passport&#39;s way of keeping track of things.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For accomplishing this task, serializeUser() function must be defined. The code for this function is provided below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/634520138f0bbee1dfdcf0c454c34130.js&quot;&gt;&lt;/script&gt; &lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the deserializeUser() function, the email id is given as the first parameter which is same email id that was passed in the serializeUser() function. Then this function makes a request to the database to find email id of the user by invoking done() function. After this step, the email id of the user is attached to the &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;box-sizing: inherit;&quot;&gt;req.user&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/2e786bbbb3cc700cb423d50d24750149.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Finally, The Application That We Will Build&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;We will be building a simple web application that will explain how to work with passport local module which is a package provided by passport js itself. We won&#39;t be storing user credentials in any database. We are doing this intentionally so that you can focus on the essential concepts related to passport js. But, in real world application, a database must be used.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Note: To follow along with this tutorial, you need to download the project file. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://drive.google.com/open?id=1EmKJ64SGNsgQ_6mHtQk7pCuKyf6hX21k&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Download Button&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYNQPH7Nz7oSSTw5WIFyDfQtchmwdX2P7-12NtEbUDBl1z_xVbI91aw65zY4XTm0cGtGsH4cKhNqxAy9-lvrHydd1pygAK3rFnh9caWVaKydMqJ2bYyPlRRtipiM7OtsUDkOM0smUy152c/s320/download_button.png&quot; title=&quot;Download Button&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Then make sure you have installed &lt;a href=&quot;https://nodejs.org/en/download/&quot; target=&quot;_blank&quot;&gt;node js&lt;/a&gt; in your computer. After download is finished extract the downloaded rar file. Open terminal or command prompt in the location where you downloaded the project. Run this command &quot;npm install&quot;, then run &quot;npm start&quot;, open a web browser and type &quot;http://localhost:8000/login&quot; to run the application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Overall Project Structure&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn_rEqocHF5P2hdssVpdRcfJ22cy45pJIiI6XLkqTXn40Lwo92nbPjoej-lUL2a3DSbru8wTe-vDlUDP8QVme0ik1Mp9WfUC16SXo8m4mAmUwcVQKphwPVbuAr-pqMZFC7dK4CARO89TCy/s1600/passport_js_overall_project_structure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Passport js Part 1 Overall Project Structure&quot; border=&quot;0&quot; data-original-height=&quot;287&quot; data-original-width=&quot;267&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn_rEqocHF5P2hdssVpdRcfJ22cy45pJIiI6XLkqTXn40Lwo92nbPjoej-lUL2a3DSbru8wTe-vDlUDP8QVme0ik1Mp9WfUC16SXo8m4mAmUwcVQKphwPVbuAr-pqMZFC7dK4CARO89TCy/s400/passport_js_overall_project_structure.png&quot; title=&quot;Passport js Part 1 Overall Project Structure&quot; width=&quot;371&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Overall Project Structure&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Discussion on project structure&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;app.js file&lt;/b&gt;: The main gateway to our express js application. Here, we will set all the dependencies, all middlewares required for the application and error handling codes etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;routes/index.js file&lt;/b&gt;: In this file, we are storing all the routes for our application. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;views folder&lt;/b&gt;: It stores all the dynamic pages for our application. For generating dynamic content for our pages, we are using handlebars as the template engine. For now, it contains two pages i.e, dashboard.hbs and login.hbs.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;public folder&lt;/b&gt;: This folder stores all the  static resource files(i.e, css,js, image files etc) required by the dashboard.hbs and login.hbs pages.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;package.json file&lt;/b&gt;: It stores various modules that are required for building the application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating The Node Server&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/ce52b4fb7f9f4bb6497e4eb0e6fbc406.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Explanation of the app.js file&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In app.js, we need to store all the references to third party modules that are used for the application. Then we need to configure them accordingly. One important note I would like to mention here, if we are using express-session module in our application, then we must configure passport middleware just after express-session middleware setup.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Configuring Passport&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/17aff9b2a64f3952671bbd656121351b.js&quot;&gt;&lt;/script&gt; &lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I already explained how this configuration actually works. If you want to revisit that section, go to the heading entitled &lt;b&gt;&quot;Topics Covered In This Article&quot;&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
Creating The Login Page&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/4fb7e73be8de81b202abd7ee4a86310f.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
Creating The Dashboard Page&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;https://gist.github.com/NileshSanyal/5c44dbac76a463ff0920c38910494570.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
Conclusion&lt;/h3&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 400;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 400;&quot;&gt;Thank you for going through this article. If you learn something new and exciting, please share this article among others.&lt;/span&gt;&lt;/h3&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;noto serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap;&quot;&gt;
 &lt;/h3&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/08/passport-js-complete-guide-part-one.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3LD4etmpG5_GSuDOoo8PksKd08gSHaOrvl_aX1gvdxZDURZoesctlGC5OMVYO3WO1_Ahcl2GmV0-WoKFX39ZlhfAURZaI71_lgYPTznpi0Uy6pMV-RJRltbn0fQTCgkNP6-46iQNlW-Xo/s72-c/passport_js.jpg" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-6852291989238716289</guid><pubDate>Sat, 17 Aug 2019 09:26:00 +0000</pubDate><atom:updated>2023-03-08T16:10:04.276+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>Top Risks Of Components With Known Vulnerabilities in 2019</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh96t7HH52sA9PLy4EOcuArIupBHnmNwp25LOaElDcoO-9nX4FIwpUA3lvbUQjmmtFKwviq-LOQUCZSbAbn1THGG8RS3e6NWHl9_8Zk_fzRn5a5Baxx3DKfBYts3YS3_aQW16PlxL04zL72/s1600/components_with_known_vulnerabilities.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Components with known vulnerabilities&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;640&quot; height=&quot;480&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh96t7HH52sA9PLy4EOcuArIupBHnmNwp25LOaElDcoO-9nX4FIwpUA3lvbUQjmmtFKwviq-LOQUCZSbAbn1THGG8RS3e6NWHl9_8Zk_fzRn5a5Baxx3DKfBYts3YS3_aQW16PlxL04zL72/s640/components_with_known_vulnerabilities.jpg&quot; title=&quot;Components with known vulnerabilities&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Components with known vulnerabilities&lt;/b&gt; is of the vulnerability  in the OWASP top 10 vulnerabilities list. It holds 9th position in the OWASP list of ten most critical web application security risks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Lots of open source plugins or components or libraries are already available on the web. Web applications make use of them a lot.  By using these components, developers save some amount of development time.  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Reasons Behind Components With Known Vulnerabilities&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Due to the pressure of quickly delivering at speed, developers often forget to properly check these libraries. This is a common problem for some small and sometimes medium sized companies. They use PHP, Javascript, Python libraries to make their applications interactive or easy to use. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Developers generally tend to focus on securing their own code, they often don&#39;t know about all the code that is running. They forget to check issues tab of any open source project listed on GitHub. Also, they did not check if any issue status is closed or not as seen in the following screen shot.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Closed issue means that issue is fixed by one of contributors of the project.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuPF9QHUtjtGAPyYpZ-jVhxxWu1CVx7kmeOwzv2yNSOtbFjk5H8lilv1LZRlGzzHzYoUFXVLGOAWP5aVgldUGqrZr5sae7oXwDBPzJzfyrG7BC4DmLh5ONWqx8-j90UCyI4uN68ROVS-Fc/s1600/github_issues_tab.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Github issues tab&quot; border=&quot;0&quot; data-original-height=&quot;392&quot; data-original-width=&quot;1271&quot; height=&quot;196&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuPF9QHUtjtGAPyYpZ-jVhxxWu1CVx7kmeOwzv2yNSOtbFjk5H8lilv1LZRlGzzHzYoUFXVLGOAWP5aVgldUGqrZr5sae7oXwDBPzJzfyrG7BC4DmLh5ONWqx8-j90UCyI4uN68ROVS-Fc/s640/github_issues_tab.png&quot; title=&quot;Github issues tab&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; color: #555d66; font-family: &amp;quot;noto serif&amp;quot;; font-size: 13px; white-space: pre-wrap;&quot;&gt;Github issues tab&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2K2VyDHXGHuXRFQe4o7r3X1Sgo5KsKtK7wa45d3uiA-X6rwxIdjFO3eY9RJLFlFqvSxAd-53bGHCNiC9dULIMUGkDSZL8PTJH-EFfToUmCNIZKJWL2_6fD4MuvUwMx_4VBhCUOUC-fQ03/s1600/github_closed_issues.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Github closed issues&quot; border=&quot;0&quot; data-original-height=&quot;520&quot; data-original-width=&quot;1271&quot; height=&quot;260&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2K2VyDHXGHuXRFQe4o7r3X1Sgo5KsKtK7wa45d3uiA-X6rwxIdjFO3eY9RJLFlFqvSxAd-53bGHCNiC9dULIMUGkDSZL8PTJH-EFfToUmCNIZKJWL2_6fD4MuvUwMx_4VBhCUOUC-fQ03/s640/github_closed_issues.png&quot; title=&quot;Github closed issues&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; color: #555d66; font-family: &amp;quot;noto serif&amp;quot;; font-size: 13px; white-space: pre-wrap;&quot;&gt;Github closed issues&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;No one could give any gurantee that any library of an application will be fully secure.  After a library is published, security experts often found security vulnerabilities. Then they add security patches to get rid of that vulnerability. If developer fails to apply that patch the vulnerability exists.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Impacts Of Components With Known Vulnerabilities&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The impact of this attack is dependent on the vulnerable library itself. This could be &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/07/cross-site-scripting.html&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;cross site scripting&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; vulnerability or any other one. But, the attacker may be able to gain control of the whole system.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Recent Attacks Made Using Components With Known Vulnerability&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The &lt;/span&gt;&lt;a href=&quot;https://www.blackducksoftware.com/open-source-security-risk-analysis-2018&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;BlackDuck 2018 Open Source Security and Risk Analysis&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; report states that 8% of the codebases it had audited contained Apache Struts, and that 33% of those still contained the Struts vulnerability more than a year after it was fixed.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Prevening Against This Attack&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Any web application must try to use few third party libraries as possible. If more and more third party libraries are used, there are greater chance of existence of vulnerabilities in those libraries or components. The developers must remove unnecessary features along with the  dependencies that are linked in that feature. If these are not removed, they may still become the reason behind security flaw.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Components or libraries from authorized sources must be used. Signed packages will allow to ensure that there exist very less chance of modified and malicious component. &lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Security policies must be established governing component use, such as requiring certain software development practices, passing security tests, and acceptable licenses.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Keep the components or libraries up to date.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Monitor the security of these components in public databases, project mailing lists, and security mailing lists.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Conclusion&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope after reading this article you properly understood the problems occurred by &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;components with known vulnerabilities&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. If you like this article share it with others. Thanks!&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/08/components-with-known-vulnerabilities.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh96t7HH52sA9PLy4EOcuArIupBHnmNwp25LOaElDcoO-9nX4FIwpUA3lvbUQjmmtFKwviq-LOQUCZSbAbn1THGG8RS3e6NWHl9_8Zk_fzRn5a5Baxx3DKfBYts3YS3_aQW16PlxL04zL72/s72-c/components_with_known_vulnerabilities.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-3747400781978668942</guid><pubDate>Sat, 10 Aug 2019 10:05:00 +0000</pubDate><atom:updated>2023-03-08T16:10:06.875+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>3 Challenges You Could Be Faced By Xml External Entity Injection</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh956aPPR9xoFj1aJ8ZYNw0C-fhyphenhyphenLO9-Pjalr6j7qRscEG_s3e2Zn31cDVmaFlrcYMWUPBjnUvWXBOuFTfv6sN8rECmNDT_HBxm9KzcIaPn-W9OSiA494bEDgo7xzN9h5gbZgyiLMJUCj6O/s1600/xml-external-entity-injection.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;XML External Entity Injection Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;426&quot; data-original-width=&quot;640&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh956aPPR9xoFj1aJ8ZYNw0C-fhyphenhyphenLO9-Pjalr6j7qRscEG_s3e2Zn31cDVmaFlrcYMWUPBjnUvWXBOuFTfv6sN8rECmNDT_HBxm9KzcIaPn-W9OSiA494bEDgo7xzN9h5gbZgyiLMJUCj6O/s640/xml-external-entity-injection.jpg&quot; title=&quot;XML External Entity Injection Cover Image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
&lt;br /&gt;
&amp;nbsp;What is XML External Entity Injection?&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;There are many ways to store and transport data for both human readable 
format and machine-readable format. Web services, web or mobile 
applications, content management systems (CMS) uses  extensible markup 
language(XML).  It is the responsibility of the developer to properly 
validate the XML data that is used for input.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;In simple words, XML external entity injection is an 
attack that is generally done to compromise the logic of an XML 
application. This injection attack is one vulnerability listed in OWASP 
top 10 vulnerabilities. If you want to know more about the other 
vulnerabilities, you can read about it &lt;a href=&quot;https://www.devhelperworld.in/2019/06/web-application-security.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
What Can Be Done With XML External Entity Injection?&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Attacker can use this injection attack to cause various types of attacks, which are as follows.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
Viewing files stored on the application server:&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
Attacker will be able to view files stored in the server if the &lt;a href=&quot;http://www.stylusstudio.com/xml/parser.html&quot; target=&quot;_blank&quot;&gt;xml parser&lt;/a&gt;
 is able to process external entities. Then the web server may return 
contents of a file on the system containing sensitive data.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
The shocking fact is, attacker is not limited to system files. They can 
also steal source codes if they know the location and structure of the 
web application. Some xml parser may also allow attackers to send HTTP 
requests to files on the local network.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
Performing Denial Of Service (DOS) attack:&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt; Another name of this attack is known as Billion Laugh Attack. The 
attacker writes the XML document in such a way so that the XML parser 
continues to expand each entity within itself. This process keeps on 
going until it overloads the server and finally brings down it.&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
Performing Server-side Request Forgery attack:&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;In some situations, web applications need to fetch data from external 
resources or some resources that can be internal services. For example, 
if developer wants to get weather data he or she may use a third party 
web api such as &quot;open weather map api&quot;.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;For example, to get current weather of London with this web api, the developer can use following URL:  &lt;a href=&quot;https://samples.openweathermap.org/data/2.5/weather?q=London,uk&amp;amp;appid=b6907d289e10d714a6e88b30761fae22&quot;&gt;https://samples.openweathermap.org/data/2.5/weather?q=London,uk&amp;amp;appid=b6907d289e10d714a6e88b30761fae22&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
If somehow the attacker is able to change the url parameter to 
localhost, then he or she will be able to view the resources that are 
hosted locally on the server. This would cause the web application 
vulnerable to server-side request forgery (SSRF).&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
What are different Types Of XML Injection Attacks?&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
There are two different types of XXE attacks, namely: in-band XXE and out-of-band XXE.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
1.&amp;nbsp;&lt;strong data-rich-text-format-boundary=&quot;true&quot;&gt;In-band XXE&lt;/strong&gt;: After performing this type of XXE attack, attacker is able to get an immediate response to the XXE &lt;a href=&quot;https://en.wikipedia.org/wiki/Payload_(computing)&quot;&gt;payload&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
2.&amp;nbsp;&lt;strong data-rich-text-format-boundary=&quot;true&quot;&gt;Out-of-band XXE&lt;/strong&gt;: This type of XXE attack does not return any immediate response from the web application on which this attack is performed.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
Where XML Injections are Possible In a XML Document?&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;In the CDATA section.&lt;/li&gt;
&lt;li&gt;In the attributes of the nodes.&lt;/li&gt;
&lt;li&gt;In the node values.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
How To Prevent Against XML Injection Attacks&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
You should disable your application&#39;s xml parsing capabilities that your
 application don&#39;t intend to use. You should consult the documentation 
of your xml parsing library for details on how to disable those 
features. For a quick reference, you can consult &lt;a href=&quot;https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md&quot; target=&quot;_blank&quot;&gt;this cheat sheet&lt;/a&gt; maintained by OWASP.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot;&gt;
Final Words&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
If you find this article about  &lt;strong&gt;XML external entity injection&lt;/strong&gt;  as helpful, please share it among others. Thank you!&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/08/xml-external-entity-injection.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh956aPPR9xoFj1aJ8ZYNw0C-fhyphenhyphenLO9-Pjalr6j7qRscEG_s3e2Zn31cDVmaFlrcYMWUPBjnUvWXBOuFTfv6sN8rECmNDT_HBxm9KzcIaPn-W9OSiA494bEDgo7xzN9h5gbZgyiLMJUCj6O/s72-c/xml-external-entity-injection.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-5029885940204472485</guid><pubDate>Sat, 03 Aug 2019 09:10:00 +0000</pubDate><atom:updated>2023-03-08T16:10:10.357+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>Four Ways To Stop Security Misconfiguration in 2019</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQROxC0c6zxZ4kxkvba2zp-2rEksOSIvo4-OlcIToTkju-H01C777OOMXmkwr5WXa-tImE5dnlA-M8n-3piaOrOOXoWOOzpUL4Ge-fgZwgfxHT8tmOnYORRC7Y_4g4K8UzXP7-rf8CnLLk/s1600/security-misconfiguration.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Security Misconfiguration Image&quot; border=&quot;0&quot; data-original-height=&quot;479&quot; data-original-width=&quot;640&quot; height=&quot;478&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQROxC0c6zxZ4kxkvba2zp-2rEksOSIvo4-OlcIToTkju-H01C777OOMXmkwr5WXa-tImE5dnlA-M8n-3piaOrOOXoWOOzpUL4Ge-fgZwgfxHT8tmOnYORRC7Y_4g4K8UzXP7-rf8CnLLk/s640/security-misconfiguration.jpg&quot; title=&quot;Security Misconfiguration&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;br /&gt;
What is Security Misconfiguration Vulnerability&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Security misconfiguration&lt;/b&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;vulnerability is one of top 10 vulnerability of OWASP. If you missed the whole list of OWASP, you can read it &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/06/web-application-security.html&quot; style=&quot;font-family: lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.It happens when the security settings are implemented, configured as default settings. Generally, the web application requires many different components in order to function correctly. It requires various resources that are as follows. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;A web server to host the application.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;An application framework to simplify management, the complexity and maintainability of the codebase.                                                        &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; A database for storing application specific data in either relational or non-relational way. &lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;Also, it may require additional resources that may vary depending on the type and complexity of the web application.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Any level of an organization&#39;s application stack can become main reason to cause a configuration flaw. If more levels are involved in the stack, the greater chances are there for a mistake leading to a vulnerability.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;security misconfiguration&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; can happen at any level of the web application stack whether be it the framework, application server, database etc.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Security Misconfiguration With Example&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;As the application grows, it becomes hard to clear the issues regarding the &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;security misconfiguration&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. It can occur in developer&#39;s own code, or in the preexisting features. Sometimes, developers create credentials to test the functionality of a web application. But, after test is done successfully, they often forget to remove the test accounts. The consequences of this mistake can lead to misconfiguration vulnerability. Attacker can exploit this and can cause severe damage the web application, thus affecting the financial growth of a business.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Sometimes, unused and unnecessary features can cause a lot of trouble to the application. For example, developers had enabled debugging mode during development phase. After the application goes live, they forgot to turn off this mode, this could prove fatal. The debugging mode displays a lot of internal information regarding the application. So an attacker can easily discover more vulnerabilities with the help of this information.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Other example of unused features could be the use of unused ports that are enabled during development phase. If these features are not turned off or they are poorly maintained, it enables attackers to further exploit the application by gaining more information and causing massive attacks on the application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Another example could be such that directory traversal is not disabled on the server where the application is hosted. Attacker could exploit this feature by traversing through the files on server, then they could be able to access configuration files on the server. This allows them to &lt;/span&gt;&lt;a href=&quot;https://www.slideshare.net/rockkotak/information-gathering-30615448&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;gather more information&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; and exploit the application.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What is Impact Of Security Misconfiguration&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The root cause of this vulnerability can leave an application completely open to attackers. In some situations, it may leave data without any need for an attack.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;One notable incident of this attack happened on October 2014. Security journalist Brian Krebs reported vulnerability in the website of &lt;/span&gt;&lt;a href=&quot;https://krebsonsecurity.com/2014/10/huge-data-leak-at-largest-u-s-bond-insurer/&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;MBIA Inc&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. Main reason of that attack was misconfigured database server. That allowed search engines to index hundreds of user account statements. Which allowed the data to be easily accessible  by a simple web search.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Also, this vulnerability could result in full takeover by the attacker. That could mean sensitive data would be stolen and  it would cost a lot of money to recover from such loss.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
How To Prevent Security Misconfiguration&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;The root cause of &lt;span style=&quot;box-sizing: inherit; font-weight: 600;&quot;&gt;security misconfiguration&lt;/span&gt; is due to human error, rather than  other attack factors. If a properly maintained and well-structured development cycle is used, it will definitely help to encounter with this vulnerability.  A proper process cycle should be used in order to secure and test during the development phase.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;To deal with inconsistent configuration issues, you need to use the same configuration options for different phases of development (e.g, development, staging and production).&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;It is a good practice to perform scans and audits on a regular basis.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Plan the architecture and then setup the system in such a way so that it will be easy enough to deploy software updates and patches. Also follow good guidelines for security configurations.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;If you are interested to learn more about ethical hacking, visit &lt;a href=&quot;https://www.vpnmentor.com/blog/ultimate-guide-to-ethical-hacking/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Final Words&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope you find this article on &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;security misconfiguration&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; as helpful. It would be great to share this content among the others if you think this post provides some value to you. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/08/security-misconfiguration.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQROxC0c6zxZ4kxkvba2zp-2rEksOSIvo4-OlcIToTkju-H01C777OOMXmkwr5WXa-tImE5dnlA-M8n-3piaOrOOXoWOOzpUL4Ge-fgZwgfxHT8tmOnYORRC7Y_4g4K8UzXP7-rf8CnLLk/s72-c/security-misconfiguration.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-4348486899237952270</guid><pubDate>Tue, 30 Jul 2019 15:39:00 +0000</pubDate><atom:updated>2023-03-08T16:10:12.580+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>7 Ways To Put An End To Sensitive Data Exposure in 2019</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLR2_2zvPPTD3-QFSP1mKpIxHzPoyAKG1kKVnBgdL684KZ0-WJJA8XEPmvR1tdamBXwp_5diNrs8C4te43s5-jHvdmy3DDucb6ou0TpWForlSY9g3wR9f7WAqjKOqDVpHzajrKtj8zYyaX/s1600/sensitive-data-exposure-cover-image.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Sensitive Data Exposure Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;578&quot; data-original-width=&quot;640&quot; height=&quot;578&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLR2_2zvPPTD3-QFSP1mKpIxHzPoyAKG1kKVnBgdL684KZ0-WJJA8XEPmvR1tdamBXwp_5diNrs8C4te43s5-jHvdmy3DDucb6ou0TpWForlSY9g3wR9f7WAqjKOqDVpHzajrKtj8zYyaX/s640/sensitive-data-exposure-cover-image.jpg&quot; title=&quot;Sensitive Data Exposure Cover Image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;br /&gt;
What Is Sensitive Data Exposure Vulnerability&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Sensitive data exposure&lt;/b&gt; &lt;a href=&quot;https://www.devhelperworld.in/2019/06/web-application-security.html&quot; target=&quot;_blank&quot;&gt;vulnerabilities&lt;/a&gt; can occur when an application does not adequately protect sensitive information. This is also known as data breach. Depending on the type  of web application the data can vary and anything from credit card details, session tokens, passwords etc can be exposed.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In most data breach cases, files, documents, sensitive information are involved. At the time of building the web application, many of the web developers down prioritize protection of sensitive information. They mostly give preference to making an application that is functionally working and correct. After completely building the application, they simply forget to add protection, or they skip that step.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
What are The Causes Of This Attack&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Lack of implementation of input sanitization.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Missing of required browser headers while sensitive information is sent to the browser.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Implementation of faulty key management.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Implementation of outdated or obsolete cryptographic algorithms.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Sensitive data is either sent or stored in the plain text format.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt; This attack can be caused by external or internal manner, a dissatisfied employee could cause more threat than an outsider. As the employee is already aware of the company&#39;s internal matters and has access to company&#39;s information. &lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Impact Of Sensitive Data Exposure&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This attack compromises user accounts and data.  After the successful execution of this attack, the data is exposed to the attacker, so he or she can do whatever he or she wants to do with it. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;An attacker can also apply his or her social engineering skills to lure the victim to click malicious links that may install some malware in the victim&#39;s computer.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This attack can be financially devastating to a website or business. It may cause reputation damage too.  In 2019, &lt;/span&gt;&lt;a href=&quot;https://gizmodo.com/885-million-sensitive-records-leaked-online-bank-trans-1835016235&quot; style=&quot;background-color: white; box-sizing: inherit; color: #00a0d2; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;885 million records containing bank transaction data were compromised&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; as a result of data breaches.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
How To Prevent Sensitive Data Exposure&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
i) Avoid storing or transmitting data in plain text format &lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;You should never use plain text format when storing some sensitive data like credit card numbers, password etc. You need to encrypt the data using strong algorithms, and ensure your website algorithm utilizes hashing for storing passwords.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
ii) Make use of SSL Certificates&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Install SSL certificate on your website, to protect the data as it transfers from your site to the server. Popular browsers like google chrome and firefox identifies sites without SSL as &quot;insecure&quot;, so it&#39;s a good practice to put your visitors&#39; minds at ease.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
iii) Use Strong Passwords&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Make sure you use passwords that are hard to guess and very strong. Also, change your passwords in a regular basis.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
iv) Keep a Backup Of The Stored Data Separately From Your Website&#39;s Server&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If somehow your server is breached, any data stored on your site, will be at risk. If you keep a backup of the data then if one copy of the data is compromised, the other isn&#39;t. So you can easily restore your site from a clean and secure copy.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
v) Use a Web Application Firewall (WAF)&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Attackers often use automated bots to launch attacks against the web site. To prevent them from doing so use WAF.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
vi) Use a Vulnerability And Malware Scanner&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Attackers often uses backdoor files that enables them to find and exploit sensitive data. Use malware scanner to check and remove the backdoor successfully.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
vii) Never Allow Browsers To Store Sensitive Data&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Make sure that browser headers do not use caching and save login or other credentials. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Final Words&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope this article helps you to understand &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;sensitive data exposure&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; in depth. If you find this article as helpful, don&#39;t forget to share with others. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/sensitive-data-exposure.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLR2_2zvPPTD3-QFSP1mKpIxHzPoyAKG1kKVnBgdL684KZ0-WJJA8XEPmvR1tdamBXwp_5diNrs8C4te43s5-jHvdmy3DDucb6ou0TpWForlSY9g3wR9f7WAqjKOqDVpHzajrKtj8zYyaX/s72-c/sensitive-data-exposure-cover-image.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-5519189783907083249</guid><pubDate>Mon, 29 Jul 2019 15:33:00 +0000</pubDate><atom:updated>2023-03-08T16:10:14.979+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>The Best way To Protect Your Application Against Broken Authentication</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXJoidghNtICWsZQxjjxM99xl4UBpOmWQOczbKm_U053wNUEDu3Xn4PF-fVnkRlEmyr7SBwe9-Ibt8jdozW2JNFkFStJ7S53iPwPVMvxZxgMcWG-2slk7zvEO6VUiOuCa2fq9_ueTosbTW/s1600/broken_authentication.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Broken Authentication Image&quot; border=&quot;0&quot; data-original-height=&quot;1067&quot; data-original-width=&quot;1600&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXJoidghNtICWsZQxjjxM99xl4UBpOmWQOczbKm_U053wNUEDu3Xn4PF-fVnkRlEmyr7SBwe9-Ibt8jdozW2JNFkFStJ7S53iPwPVMvxZxgMcWG-2slk7zvEO6VUiOuCa2fq9_ueTosbTW/s640/broken_authentication.jpg&quot; title=&quot;Broken Authentication&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;br /&gt;Broken authentication&lt;/b&gt; vulnerability is one of the vulnerability listed in OWASP top 10 vulnerabilities. If you don&#39;t know about OWASP top 10 vulnerabilities, you can read it &lt;a href=&quot;https://www.devhelperworld.in/2019/06/web-application-security.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. It exists in web application due to improper implementation of session management and authentication functions. The consequences due to this ignorance may prove to be severe. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Impact Of Broken Authentication Vulnerability&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;An attacker can compromise the passwords, keys, or session tokens and then eventually they can gain access any user account.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;This vulnerability allows attacker to attack some or all accounts. After successful execution of this attack, attacker is able to do anything the victim is able to do.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Before we deep dive into the details on this type of vulnerability, we need to have solid understanding of 3 things in particular. These are: Session, Cookie and Authentication.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Session&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, in simple words, session is a way for the server to identify users and persist users activity across a web application. To achieve this, server maintains a storage for storing all users sessions. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;When users login to their account, that time server generates a session with the help of something that is known as &lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Session_ID&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;Session ID&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. This step is a must for the server, as the communication between client and server is established with the help of HTTP protocol. If you don&#39;t know what HTTP is, read more about it &lt;/span&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/07/web-programming-basics.html&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Since, server generates a session id for the user, client (the browser) does not need to provide its information on every subsequent requests. The browser stores the session id inside a cookie. When a new request is sent to the server, the cookie acts as an authenticity on behalf of the client. When user clicks the logout link, the server terminates the user&#39;s activity and the cookie residing in the browser is deleted.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Cookie&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Cookie is basically a text file that a web browser stores in the user&#39;s computer. The main purpose of a cookie is to maintain application state. Common use cases of cookies are as follows...&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Keeping user&#39;s preferences within the website, so that next time the user visits in the site, he or she can see the content that he or she prefers the most.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt; Storing the information about the browser that is used to browse the site.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;To remember user&#39;s registered login credentials.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Authentication&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Authentication is process of verifying a user&#39;s identity. Generally, authentication involves checking email id and password of a user with the correct credentials. Bio metrics is a better approach to implement authentication. As it requires users to verify their identity with their biological characteristics (e.g, fingerprint or retina ).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Protect Against Broken Authentication&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul aria-autocomplete=&quot;list&quot; aria-label=&quot;Write list…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: Lato, sans-serif; font-size: 16px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 0px 1.3em; outline: none; padding: 0px 0px 0px 1.3em; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Avoid using URL query strings for session id or any user or session information.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Entire session should be transmitted via HTTPS to prevent disclosure of the session id.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Protect any session information transmitted to or from the client.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Implement time-out on the server or expire the session when the user is idle.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;Generate random and complex session id that cannot be guessed easily.&lt;/li&gt;
&lt;li style=&quot;box-sizing: inherit; margin-bottom: initial;&quot;&gt;It would be a better choice if a new session is regenerated after authentication is successful.&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Conclusion&lt;/h2&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope after reading this article you have clear concept on &lt;b&gt;broken authentication&lt;/b&gt;. If you find this article helpful, please share it among with the others. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/broken-authentication.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXJoidghNtICWsZQxjjxM99xl4UBpOmWQOczbKm_U053wNUEDu3Xn4PF-fVnkRlEmyr7SBwe9-Ibt8jdozW2JNFkFStJ7S53iPwPVMvxZxgMcWG-2slk7zvEO6VUiOuCa2fq9_ueTosbTW/s72-c/broken_authentication.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-4950195283238887445</guid><pubDate>Sat, 27 Jul 2019 10:09:00 +0000</pubDate><atom:updated>2023-03-08T16:10:17.352+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>The Web Programming Basics You Must Know For Sure</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnIhRj_ETQGZBzMADeY-l0S9hlT7ZZGMdZ_EKF2-f0yd3Iqs_VdPU_BXG8M05hFRS-bK4ZtrHHXhseEQx7X0NvD5Cxn9HDeFCgnqtnMj2LZitLZRP1p0Fgl2TE8oALbxixO5fCumGtrdiX/s1600/web_programming_basics.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Web Programming Basics&quot; border=&quot;0&quot; data-original-height=&quot;1067&quot; data-original-width=&quot;1600&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnIhRj_ETQGZBzMADeY-l0S9hlT7ZZGMdZ_EKF2-f0yd3Iqs_VdPU_BXG8M05hFRS-bK4ZtrHHXhseEQx7X0NvD5Cxn9HDeFCgnqtnMj2LZitLZRP1p0Fgl2TE8oALbxixO5fCumGtrdiX/s640/web_programming_basics.jpg&quot; title=&quot;Web Programming Basics&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;br /&gt;Web programming&lt;/b&gt; refers to the programming that involves writing, markup and coding in order to create web pages. Typically, two different paths exist in this regard. One path is called as front-end and another as back-end.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Front-end and Back-end Programming&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Front-end technology mainly deals with what is actual look and feel of the web page, it is used to create user interface of a web page, whereas back-end technology deals with functionalities of the web page.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Front-end and Back-end Programming Use cases&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s understand front-end and back-end technology use-cases in a real world scenario. Suppose, you open facebook.com in the browser. Then what you actually see in the browser is created using front-end technology. When you try to log in to facebook by entering email address and password, then the credentials provided by you is checked against the email, password that is stored in facebook&#39;s remote server and if it is correct you are redirected to the dashboard page of facebook. This functionality is implemented with the help of back-end technology.  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Most common languages used for front-end programming are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;HTML&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;CSS&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Javascript&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Languages used for back-end programming are as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Java&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;a href=&quot;https://www.devhelperworld.in/2019/06/php-code-injection.html&quot; target=&quot;_blank&quot;&gt;PHP&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;Python&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; white-space: pre-wrap;&quot;&gt;Ruby&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In this article, you will know each concepts that is related to web programming, after you finished reading this article, you will have a solid grasp of knowledge on web programming.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Web Application&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;A web application is a type of application that is capable of displaying dynamic content. The contents are dynamic as server-end generates all of the contents depending on the request made by the client end (the browser).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Ok, I got it, web application is dynamic one,right? But tell me what is a Web site?&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In simple words, a web site is a collection of web pages that has static content. If a user is browsing a web site, he or she will see pages whose contents will not change based on different request made from the browser.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Introduction To Inner-workings of a Web site&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; Web consists of billions of&amp;nbsp;clients&amp;nbsp;and server connected through wires and wireless networks. Here, the client refers to any device that sends requests to the server . The server is a computer or workstation that can be located anywhere in the world .&amp;nbsp;Clients send requests to web server,&amp;nbsp;the server receives the request, finds the resources and&amp;nbsp;sent&amp;nbsp;the response back to the&amp;nbsp;client.&amp;nbsp; The&amp;nbsp;client&amp;nbsp;uses&amp;nbsp;some type of application program(i.e, browser)&amp;nbsp;to send request to the server. The server&amp;nbsp;typically&amp;nbsp;sends response to the browser with&amp;nbsp;HTML(Hyper Text Markup Language). Then the browser interprets the HTML and then renders the web page. After this process is finished we are able to see the web page in browser.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY3OFVS58nK9dijZLJZznqmljyosGQLcXc22SyRiakpCy48CI6D5s_FbNmg4Ejpr4-bPI30r_xyM-bi98vdNRbifsf6lejNik03JUGLz83-zGQew9tVXmP9KiLpKpiMGy18_-oWWCoBxES/s1600/Client+Server+Communication.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Client Server Communication&quot; border=&quot;0&quot; data-original-height=&quot;388&quot; data-original-width=&quot;712&quot; height=&quot;348&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY3OFVS58nK9dijZLJZznqmljyosGQLcXc22SyRiakpCy48CI6D5s_FbNmg4Ejpr4-bPI30r_xyM-bi98vdNRbifsf6lejNik03JUGLz83-zGQew9tVXmP9KiLpKpiMGy18_-oWWCoBxES/s640/Client+Server+Communication.png&quot; title=&quot;Client Server Communication&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Client Server Communication&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Mode Of Communication Between Server and Client&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Communication between server and client is established via something that is known as &lt;/span&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol&quot; style=&quot;background-color: white; box-sizing: inherit; color: #007fac; font-family: Lato, sans-serif; font-size: 16px; outline: 0px; transition-duration: 0.05s; transition-property: border, background, color; transition-timing-function: ease-in-out; white-space: pre-wrap;&quot;&gt;HTTP&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; (Hypertext Transfer Protocol). HTTP is a protocol, protocol refers to a set of predefined rules that must be mutually accepted by both server and client in order to smoothly transmit data between them.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;HTTP allows simple request and response communications between client and server. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h2 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.95em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Different Types Of HTTP Methods&lt;/h2&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;There are 7 different types of HTTP methods available, but most often 2 of them are used frequently. These methods are GET and POST methods.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
GET Method &lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;This method is primarily used to fetch data from the server. If some data needs to be sent through this method, then that data needs to be encoded first in order to send them to the server.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;GET is the default method when the browser tries to send data to the server and it produces a long text that is visible to the browser&#39;s address bar. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;For example, when you open Google.com and type a query and hit search, you will see something similar as shown in the screenshot below.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixQn9DSoKSb6I7IRhZHvvpn5f0_8-GV5qqazt29XTH63nlD_WlM28TIMWzzbkmOAfqOLd-BvEjDOOWQt8W8mcXwGOadovoobMFDCvn7cuATzno6PG349pfZiJghRClVI0uClqE-OEKIyPw/s1600/GET+Method+Example.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;GET Method Example&quot; border=&quot;0&quot; data-original-height=&quot;124&quot; data-original-width=&quot;1139&quot; height=&quot;68&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixQn9DSoKSb6I7IRhZHvvpn5f0_8-GV5qqazt29XTH63nlD_WlM28TIMWzzbkmOAfqOLd-BvEjDOOWQt8W8mcXwGOadovoobMFDCvn7cuATzno6PG349pfZiJghRClVI0uClqE-OEKIyPw/s640/GET+Method+Example.png&quot; title=&quot;GET Method Example&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;GET Method Example&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Explanation of Above Example&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If you carefully observe the highlighted red rectangle, you will see &amp;amp;q=how+to+google. Here, &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;&amp;amp;q&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; refers to the search query. The &amp;amp; symbol is required as it is required to separate different query parameters used in the GET method. After you mention the search keyword in an encoded format google can understand that quiet easily. During encoding process, the blank space character is converted to &#39;+&#39; symbol.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
POST Method&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;The main purpose of using this method is to request for some resource to the server. At the same time it is also capable of sending form data to the server. This method is more reliable compared to GET method as the data that you send through POST method is not visible in the browser&#39;s address bar.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Conclusion&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;I hope you have found this article about web programming as helpful to you. If you do so, please share it among others. As you know sharing is caring. Thank you!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/web-programming-basics.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnIhRj_ETQGZBzMADeY-l0S9hlT7ZZGMdZ_EKF2-f0yd3Iqs_VdPU_BXG8M05hFRS-bK4ZtrHHXhseEQx7X0NvD5Cxn9HDeFCgnqtnMj2LZitLZRP1p0Fgl2TE8oALbxixO5fCumGtrdiX/s72-c/web_programming_basics.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-8456137858200984692</guid><pubDate>Sun, 21 Jul 2019 16:15:00 +0000</pubDate><atom:updated>2023-03-08T16:10:19.520+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>Object Oriented Programming Principles You Must Know</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkbszLcePpTiam5-M_F3so2T5MZtgllityVtDALOcoh7P5ZR0_5I_KhImdG6-OYiku4OC2JIFQziU2xSpFOl0j3ddadvXlbT3WbyCFW4Bc9Hux1jtJC6MuBpagy4dPhfG8ZOWOaIflSHxL/s1600/oop-principles.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;oop principles&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkbszLcePpTiam5-M_F3so2T5MZtgllityVtDALOcoh7P5ZR0_5I_KhImdG6-OYiku4OC2JIFQziU2xSpFOl0j3ddadvXlbT3WbyCFW4Bc9Hux1jtJC6MuBpagy4dPhfG8ZOWOaIflSHxL/s640/oop-principles.jpg&quot; title=&quot;oop principles&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; text-align: left; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; text-align: left; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; text-align: left; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; text-align: left; white-space: pre-wrap;&quot;&gt;The core concept behind &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-weight: 600;&quot;&gt;object oriented programming&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; text-align: left; white-space: pre-wrap;&quot;&gt; is to tie together data with operations that do things with it. Main intention of doing so is to make sure that no other part of the code can access this data except the function.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Why Object Oriented Programming?&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b style=&quot;color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Achieving Modularity&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;: It enables us to write programs in a modular approach. A large program is divided into several smaller programs, each of them is known as a module. By using modular programming paradigm, it enables us to write large complex programs in more maintainable smaller chunks of programs.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;Reducing Code Duplication&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;box-sizing: inherit; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; font-weight: 600; white-space: pre-wrap;&quot;&gt;With Inheritance&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;: It reduces code duplication by using a concept known as inheritance. Suppose, we want to represent a Car and a Racing Car with &lt;span style=&quot;font-weight: 600;&quot;&gt;object oriented programming&lt;/span&gt;. Both Car and Racing Car have some similarity between them, but Racing Car may have some extra features and functionalities that the normal Car don&#39;t have. By applying inheritance, we can easily represent these type of features without code duplication.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;b style=&quot;color: #191e23; font-family: Lato, sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Achieving Flexibility With Polymorphism&lt;/b&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;: Let&#39;s assume, we want to add drive functionality to both Car and Racing Car. Instead of creating driveCar() and driveRacingCar() functions, we just create a drive() function and we pass a parameter representing the type of car object (it can be car or racing car) to that function. So, depending on the type of car object, the drive() function will be called accordingly at runtime.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Building Blocks Of Object Oriented Programming&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Class:&lt;/b&gt;&amp;nbsp;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;It is the most primary block of &lt;b&gt;object oriented programming&lt;/b&gt;. You can think of class as a way to represent user defined data type. Class acts as a glue that keeps data members and member functions together. Class represents the blueprint of something.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s imagine, in the Car class, there may be different cars with different name and brands. But all of them share some common features, like all of them have four wheels, speed limit, mileage range etc. So these are the car&#39;s properties or data members. Also, car can be driven by a driver, so drive is considered to be a functionality that a car must have.&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Class do not occupy any memory space, but object occupies space. &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, drive will be considered as a member function of Car class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Object:&lt;/b&gt; &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After bundling the data members and member functions together, we need to create an instance of that bundle. That instance is known as object. Creating object is necessary otherwise, we won&#39;t be able to carry out different operations on the car.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s understand this concept practically. Imagine a car factory. We create blue print of a specific car model, then we created multiple copies of it. So, blue print is the car class itself and we create multiple copies of car class based on the blue print provided.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Core Principles Of Object Oriented Programming&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;Encapsulation:&lt;/b&gt; Encapsulation refers to hiding the internal workings of an object from outside world. Generally, data members and member functions are wrapped up together as a single unit in encapsulation. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s assume, a car has parking sensors installed in it. To the outside world, it will alert the driver if the car is getting too close to an obstacle, but we are not aware about the detail inner workings of it. To the external world, there is only one switch that turns this feature on or off and rest of the complexity is hidden.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Inheritance:&lt;/b&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In simple words, inheritance refers to the capability of a class to acquire some or all of the properties of another class. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;For example, if we consider two classes Car and Racing car, then both of them are cars. So, Racing car will have some features and functionalities same as the Car. To reflect this type of relationship of two classes, we can use inheritance.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;b style=&quot;color: #191e23;&quot;&gt;Polymorphism:&lt;/b&gt;&lt;span style=&quot;color: #191e23;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Poly&lt;/span&gt;&lt;span style=&quot;color: #191e23;&quot;&gt; means many, &lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;phism&lt;/span&gt;&lt;span style=&quot;color: #191e23;&quot;&gt; means forms. So, polymorphism means &lt;/span&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;many forms&lt;/span&gt;&lt;span style=&quot;color: #191e23;&quot;&gt;. After applying polymorphism, the function that will be invoked is determined at runtime based on the type of  the object.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;lato&amp;quot; , sans-serif;&quot;&gt;Let&#39;s consider a real world example, a car have gear transmission system. It has four front gears and one backward gear. When the engine is accelerated then depending upon which gear is engaged different amount of power and movement is delivered to the car.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.56em; line-height: 1.4; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Implementing Object Oriented Programming in PHP&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Creating Class&lt;/span&gt;&lt;/h3&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw-fStg4xq5WVS3b2tirsH6Ek3ACbP9nOyXXKKNvnaaPUmrRc6E7lbG8kYUN-GVxK_5_zLI8SpcDYyMmUW6qyB0wr_AdVBnw5mOIF6XnETUl5KHLoE67DtAGilxigDjrXnLk71dWYm5ZkI/s1600/object-oriented-programming-creating-a-class.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Creating a Class&quot; border=&quot;0&quot; data-original-height=&quot;234&quot; data-original-width=&quot;682&quot; height=&quot;218&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw-fStg4xq5WVS3b2tirsH6Ek3ACbP9nOyXXKKNvnaaPUmrRc6E7lbG8kYUN-GVxK_5_zLI8SpcDYyMmUW6qyB0wr_AdVBnw5mOIF6XnETUl5KHLoE67DtAGilxigDjrXnLk71dWYm5ZkI/s640/object-oriented-programming-creating-a-class.png&quot; title=&quot;Creating a Class&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To represent all principles that we discussed above, we need to define which data members and member functions go together by placing them inside a class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, a Car class is defined, where 3 data members and 1 member function is defined. Note, the use of &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;$this&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; in &lt;/span&gt;&lt;span style=&quot;background-color: white; box-sizing: inherit; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;drive()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; function, it refers to the particular instance of the object that&#39;s currently being manipulated. The &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;&lt;a href=&quot;https://www.php.net/manual/en/language.oop5.visibility.php&quot; target=&quot;_blank&quot;&gt;protected&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; keyword acts as an access modifier that allows the data member to be accessible from within the Car class, and all the classes that inherit the Car class. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Creating Object&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;After the data members and member functions are defined within the class. We need to create an object of the class to execute various operations on that object. &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKuvvirqfOOybQJ1mFIUQBHky7SDHBgdTkV7eeQep6Itb70H5CQWMCe6xnh1Jf4GLyjmG-XHpZfbGQhvjCfzl6gZYOnvNY9rxmTP1yBDWs43ygPjlxdTrzxqurGQHSvZFcsJyyew2GtYUN/s1600/object-oriented-programming-creating-object.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Creating Object&quot; border=&quot;0&quot; data-original-height=&quot;99&quot; data-original-width=&quot;265&quot; height=&quot;147&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKuvvirqfOOybQJ1mFIUQBHky7SDHBgdTkV7eeQep6Itb70H5CQWMCe6xnh1Jf4GLyjmG-XHpZfbGQhvjCfzl6gZYOnvNY9rxmTP1yBDWs43ygPjlxdTrzxqurGQHSvZFcsJyyew2GtYUN/s400/object-oriented-programming-creating-object.png&quot; title=&quot;Creating Object&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In above code snippet, an object called &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;brand_new_car&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; is created and &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;drive&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; function is invoked on that object.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Creating Constructor&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Suppose, we want to set a value to the object at the time of creation of it. Then we can do so using one of PHP&#39;s magic methods i.e, &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;a href=&quot;https://www.php.net/manual/en/language.oop5.decon.php&quot; target=&quot;_blank&quot;&gt;__construct&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi8scK_dT3mLpejNbG_6dXQN59Ls7m5iBkfBV3Kjj_MHUDtxVLo5DkZVYs18MJIdwfMY8NMO36ui_Y0eKH-hW5mQ_Fca5N9_xKWafs0sCy2O2hhpvRjapUquXRCLqPoqfyND6VoYUWTA0D/s1600/object-oriented-programming-creating-constructor.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programmin Creating Constructor&quot; border=&quot;0&quot; data-original-height=&quot;383&quot; data-original-width=&quot;663&quot; height=&quot;368&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhi8scK_dT3mLpejNbG_6dXQN59Ls7m5iBkfBV3Kjj_MHUDtxVLo5DkZVYs18MJIdwfMY8NMO36ui_Y0eKH-hW5mQ_Fca5N9_xKWafs0sCy2O2hhpvRjapUquXRCLqPoqfyND6VoYUWTA0D/s640/object-oriented-programming-creating-constructor.png&quot; title=&quot;Creating Constructor&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;So, we created a constructor that takes a single parameter called &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #0b5394; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;new_speed&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;. Then we assigned the value to the car class&#39;s own data member (i.e, &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #3d85c6; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;speed&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;). Later we invoked the constructor by passing a value at the time of creating object of the car class.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Creating Static Data Members&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If we want to store some data that pertains to the class rather than to any one instance of the class. Then we can use &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #b45f06; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; keyword to do so.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRik1IKWdtoUSPCDezcpiGCdH2Wa0bRdJlQCOL56_a0sUEM9fd5PmOcZ02kJN67RRSAqzPy5O9IMBSiW24ykyCGoXWuB7HVSgP2iAr2INcH7MP30SPZtG34fTsYqrjpkKfDvjN8jqebkOV/s1600/object-oriented-programming-creating-static-data-member.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;object Oriented Programming Creating Static Data Member&quot; border=&quot;0&quot; data-original-height=&quot;186&quot; data-original-width=&quot;374&quot; height=&quot;197&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRik1IKWdtoUSPCDezcpiGCdH2Wa0bRdJlQCOL56_a0sUEM9fd5PmOcZ02kJN67RRSAqzPy5O9IMBSiW24ykyCGoXWuB7HVSgP2iAr2INcH7MP30SPZtG34fTsYqrjpkKfDvjN8jqebkOV/s400/object-oriented-programming-creating-static-data-member.png&quot; title=&quot;Creating Static Data Member&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Here, the &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #351c75; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;car_bought&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; keeps track of total number of cars bought across all car instances. This data member is a feature of the Car class itself, not any single Car object.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To access &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #b45f06; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; data members, outside the class, the &lt;a href=&quot;https://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php&quot; target=&quot;_blank&quot;&gt;scope resolution operator&lt;/a&gt; is used with the name of the class.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLozARpAe9MRStkz1ptqCyiwW3WqoxwTl0t4lCMGLUpWDTqZ8nvWII1-J1UNuBPKb1y0l8hqZyxsXN3PK5Bwiyl58pYnNVprjTwUBbj0F5cuq1aSkdiUNwXkqfNgdf_2KQT6vLnnumYHUj/s1600/object-oriented-programming-accessing-static-data-member.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Accessing Static Data Member&quot; border=&quot;0&quot; data-original-height=&quot;100&quot; data-original-width=&quot;365&quot; height=&quot;107&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLozARpAe9MRStkz1ptqCyiwW3WqoxwTl0t4lCMGLUpWDTqZ8nvWII1-J1UNuBPKb1y0l8hqZyxsXN3PK5Bwiyl58pYnNVprjTwUBbj0F5cuq1aSkdiUNwXkqfNgdf_2KQT6vLnnumYHUj/s400/object-oriented-programming-accessing-static-data-member.png&quot; title=&quot;Accessing Static Data Member&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To access it from within the class the scope resolution operator is prefixed with the keyword &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #38761d; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;$self&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXqCe_Y2VuEs1dD0FjCbu3_zfbeLNUIgnqdS0nL9nMbTzyPQd_rLi7TwUwfMHJaHH-0KaLPDZgWnKE3Elg_CNbykL8bazDEJiAPUVtiwpful217Vy8f5jajpb_ZrE1mfZN58H__C2HDU2d/s1600/object-oriented-programming-accessing-static-data-member-within-class.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Accessing Static Data Member Within Class&quot; border=&quot;0&quot; data-original-height=&quot;213&quot; data-original-width=&quot;403&quot; height=&quot;210&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXqCe_Y2VuEs1dD0FjCbu3_zfbeLNUIgnqdS0nL9nMbTzyPQd_rLi7TwUwfMHJaHH-0KaLPDZgWnKE3Elg_CNbykL8bazDEJiAPUVtiwpful217Vy8f5jajpb_ZrE1mfZN58H__C2HDU2d/s400/object-oriented-programming-accessing-static-data-member-within-class.png&quot; title=&quot;Accessing Static Data Member Within Class&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating Inheritance&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY1_kkMGl7RoW_BafTLBwGrYVcWJiEL4XDDiFderXk-1_ImiTAV-1_00Hsx1z5x5OFLopPXAbN2Sv45F09aB1tj0UfyUcnXEQEqDg86OW8BLthbyoAXlxweBzsLsxF7W5DYnSizML9y23L/s1600/object-oriented-programming-creating-inheritance.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Creating Inheritance&quot; border=&quot;0&quot; data-original-height=&quot;511&quot; data-original-width=&quot;592&quot; height=&quot;345&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY1_kkMGl7RoW_BafTLBwGrYVcWJiEL4XDDiFderXk-1_ImiTAV-1_00Hsx1z5x5OFLopPXAbN2Sv45F09aB1tj0UfyUcnXEQEqDg86OW8BLthbyoAXlxweBzsLsxF7W5DYnSizML9y23L/s400/object-oriented-programming-creating-inheritance.png&quot; title=&quot;Creating Inheritance&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;In the above code snippet, a &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;RacingCar&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; class is created that inherits from the &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Car&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; class. Then the constructor of the parent class (i.e, &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Car&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;) is called to get the value from the parent class&#39;s constructor and pass that value to the child class as well. After that, an instance of racing car is created and a member function is called to show the extra feature that racing car already possesses. Here, &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #cc0000; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Car&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; is the parent class and &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #cc0000; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;RacingCar&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt; is a child or derived class.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: red;&quot;&gt;Note:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;span style=&quot;color: #191e23;&quot;&gt; A class may be extended directly from only one class at a time in PHP.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;/h3&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;
Creating Interface&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;It allows a way to such that the member functions that child or derived classes must implement without providing an implementation. In other words, if we wanted the implementation will be done by the derived classes that will be responsible for implementing that interface, then we have to define an interface.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizX9eJLRjuT6z0nVGLPuJ8DDxiTCxv1jKCQv7bll_HN4x4AshgJRWB9fRQe3uNn5u4ZqI0YGeRc_PyCZgabhRkDumkxOl-POoZsshNInathZbpd_iW2MrGQlKb0uGnE7CRUajklZVj6nYL/s1600/object-oriented-programming-creating-interface.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Creating Interface&quot; border=&quot;0&quot; data-original-height=&quot;140&quot; data-original-width=&quot;297&quot; height=&quot;188&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizX9eJLRjuT6z0nVGLPuJ8DDxiTCxv1jKCQv7bll_HN4x4AshgJRWB9fRQe3uNn5u4ZqI0YGeRc_PyCZgabhRkDumkxOl-POoZsshNInathZbpd_iW2MrGQlKb0uGnE7CRUajklZVj6nYL/s400/object-oriented-programming-creating-interface.png&quot; title=&quot;Creating Interface&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Implementing Interface&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;If you have decalred a Car interface, then in order to use the interface, a class must implement that interface. A class can implement the interface using the keyword &lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span style=&quot;color: #38761d;&quot;&gt;implements&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8WyO6bksyNidrZ0i2ss33uTfrzNGVcY6X4dykX3fTxG6EInuNDQPH_pn6tj_0BbXB1_pHhw_o_hfd4SwTWtVil2FTwMoxOCTv7wM6IiYLsAJkvrneWofzwFs1RX5au_27qCoitymai1v7/s1600/object-oriented-programming-implementing-interface.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Implementing Interface&quot; border=&quot;0&quot; data-original-height=&quot;289&quot; data-original-width=&quot;389&quot; height=&quot;296&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8WyO6bksyNidrZ0i2ss33uTfrzNGVcY6X4dykX3fTxG6EInuNDQPH_pn6tj_0BbXB1_pHhw_o_hfd4SwTWtVil2FTwMoxOCTv7wM6IiYLsAJkvrneWofzwFs1RX5au_27qCoitymai1v7/s400/object-oriented-programming-implementing-interface.png&quot; title=&quot;Implementing Interface&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;Note:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt; A class can implement more than one interface at a time in PHP.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiFFCZN9RbHA-pV5year7BV6-qCjT72QwmyJd4A24BFcLuhjH4OIp1mz55pSM35408g8GjQ5-3ObjuGgF_GWaz5OClqwtUNNs9mndeaf3aEQ0egnNbLDVJreMJqGLV8xCl_1sn59ZlhwuN/s1600/object-oriented-programming-implementing-multiple-interfaces.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Implementing Multiple Interfaces&quot; border=&quot;0&quot; data-original-height=&quot;522&quot; data-original-width=&quot;408&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjiFFCZN9RbHA-pV5year7BV6-qCjT72QwmyJd4A24BFcLuhjH4OIp1mz55pSM35408g8GjQ5-3ObjuGgF_GWaz5OClqwtUNNs9mndeaf3aEQ0egnNbLDVJreMJqGLV8xCl_1sn59ZlhwuN/s400/object-oriented-programming-implementing-multiple-interfaces.png&quot; title=&quot;Implementing Multiple Interfaces&quot; width=&quot;312&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above code snippet, the &lt;span style=&quot;color: #b45f06;&quot;&gt;RacingCar&lt;/span&gt; class implements 2 interfaces (i.e, &lt;span style=&quot;color: #38761d;&quot;&gt;Car&lt;/span&gt; and &lt;span style=&quot;color: #38761d;&quot;&gt;SpeedyCar&lt;/span&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating Abstract Classes&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;Let&#39;s assume, you have a requirement where you want to provide part of an implementation for a class, but you do not want to allow instances of a class to be created until a more specific class extends it. &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #191e23; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px; white-space: pre-wrap;&quot;&gt;To fulfill this type of requirement, you can use abstract class.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhop-Jhx1AcPE0opmgvOo359v9BZ-_4kUCXGrcunGEQ5ed90p4Y4mYkq4parrli1Ysn9ZXRF3Az2C67MAiUa35GbOnGoEF4jivwJqVQpqnZ0U3FnuoVN_JQJQcQwJlmr7cpkWA625BSSK3-/s1600/object-oriented-programming-creating-abstract-class.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Creating Abstract Class&quot; border=&quot;0&quot; data-original-height=&quot;348&quot; data-original-width=&quot;359&quot; height=&quot;387&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhop-Jhx1AcPE0opmgvOo359v9BZ-_4kUCXGrcunGEQ5ed90p4Y4mYkq4parrli1Ysn9ZXRF3Az2C67MAiUa35GbOnGoEF4jivwJqVQpqnZ0U3FnuoVN_JQJQcQwJlmr7cpkWA625BSSK3-/s400/object-oriented-programming-creating-abstract-class.png&quot; title=&quot;Creating Abstract Class&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above code snippet, &lt;span style=&quot;color: #38761d;&quot;&gt;Car &lt;/span&gt;class is defined as an abstract class that contains an abstract function called &lt;span style=&quot;color: #351c75;&quot;&gt;drive&lt;/span&gt;. To make use of this class, you have to create a class that extends this abstract class, and then you need to create instance of the child class and invoke the method using that child class object.&lt;br /&gt;
&lt;br /&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Creating Final Method and Final Class&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you do not want to allow a method to be overwritten in a child or derived class, you can declare that method as a final method. If you try to call the final method in child class, PHP interpreter will display an error message.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivfgfEnLYtumGtqnnzeP377w_7IQXna7fEhmLvig7p98nvOTLBLHFvXL2rwfSDlRot1M7GEewgMr4qRA8sw75H9ut0Eu4yp3eXwXSTVftUF9YpSjoLcymwEn_0kcjNX_N1y9VwYRsL2ojW/s1600/object-oriented-programming-final-method-final-class.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Object Oriented Programming Final Method Final Class&quot; border=&quot;0&quot; data-original-height=&quot;343&quot; data-original-width=&quot;661&quot; height=&quot;331&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivfgfEnLYtumGtqnnzeP377w_7IQXna7fEhmLvig7p98nvOTLBLHFvXL2rwfSDlRot1M7GEewgMr4qRA8sw75H9ut0Eu4yp3eXwXSTVftUF9YpSjoLcymwEn_0kcjNX_N1y9VwYRsL2ojW/s640/object-oriented-programming-final-method-final-class.png&quot; title=&quot;Final Method Final Class&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
&lt;br /&gt;&lt;/h4&gt;
&lt;h4 aria-autocomplete=&quot;list&quot; aria-label=&quot;Write heading…&quot; aria-multiline=&quot;true&quot; class=&quot;block-editor-rich-text__editable editor-rich-text__editable&quot; data-gramm=&quot;false&quot; data-is-placeholder-visible=&quot;false&quot; role=&quot;textbox&quot; spellcheck=&quot;false&quot; style=&quot;background-color: white; box-sizing: inherit; color: #191e23; font-family: &amp;quot;Noto Serif&amp;quot;; font-size: 1.25em; line-height: 1.5; margin: 0px; outline: none; position: relative; white-space: pre-wrap !important;&quot;&gt;
Final Words&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
If you find this post about object oriented princles helpful, don&#39;t forget to share this article among others. Thank you!&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/oops-principles.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkbszLcePpTiam5-M_F3so2T5MZtgllityVtDALOcoh7P5ZR0_5I_KhImdG6-OYiku4OC2JIFQziU2xSpFOl0j3ddadvXlbT3WbyCFW4Bc9Hux1jtJC6MuBpagy4dPhfG8ZOWOaIflSHxL/s72-c/oop-principles.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-5279044155914348270</guid><pubDate>Sun, 14 Jul 2019 14:29:00 +0000</pubDate><atom:updated>2023-03-08T16:10:21.811+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>Surprising Facts About Cross Site Request Forgery</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMC1D1TBeHInTTzA2p5sRLGytTPvm1KX51nSm2m9GAOa7cRSo40e4H7c7h1wukEIUKBqgpTaOI-38eMQQ-ET8qt5ilV_IbGn7Mz8mnwRLdPWRhd_tmiSspe7jUXSzoWwzljMojayWkwLnL/s1600/Cross+Site+Request+Forgery.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Cross Site Request Forgery&quot; border=&quot;0&quot; data-original-height=&quot;847&quot; data-original-width=&quot;1280&quot; height=&quot;422&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMC1D1TBeHInTTzA2p5sRLGytTPvm1KX51nSm2m9GAOa7cRSo40e4H7c7h1wukEIUKBqgpTaOI-38eMQQ-ET8qt5ilV_IbGn7Mz8mnwRLdPWRhd_tmiSspe7jUXSzoWwzljMojayWkwLnL/s640/Cross+Site+Request+Forgery.jpg&quot; title=&quot;Cross Site Request Forgery&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;Cross Site Request Forgery&amp;nbsp;&lt;/b&gt;(also known
as CSRF) is a web application vulnerability in which attacker&#39;s
website forces victim&#39;s browser to send malicious requests to the
vulnerable website in which the victim is currently authenticated.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
To perform &lt;b&gt;Cross Site Request Forgery&amp;nbsp;attack&lt;/b&gt;, attacker tricks
a logged-in user by using social-engineering techniques to perform
some tasks on behalf of the user without their knowledge. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
The vulnerable web application is
unable to differentiate between a legitimate user request and
requests initiated a malicious website.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Why Do We Care About
Cross Site Request Forgery ?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
The damage caused by a csrf attack can
vary depending on the web application&#39;s functionality that is
vulnerable to csrf attacks. Following are the problems that can be
caused by cross site request forgery.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;Impersonation
and identity riding:&lt;/b&gt; After a csrf attack is successful, an
attacker can make requests as he or she wishes to execute on behalf
of the user. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;Modification
of account information:&lt;/b&gt;&lt;span style=&quot;color: maroon;&quot;&gt; &lt;/span&gt;If
any csrf vulnerability is found on account modification page, then
attacker can modify account details of the user after successfully
executing this attack.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;Compromised
admin account: &lt;/b&gt;If a csrf vulnerability exists in an admin
account, attackers can compromise admin account.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Understanding&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;b style=&quot;font-size: medium;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Cross Site Request Forgery&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;Attack&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
To understand csrf attack, at first we
need to know the basics of how cookies and sessions work in a web
application.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;b&gt;How
cookies and sessions Work ?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
Suppose, a user &lt;span style=&quot;color: #9900ff;&quot;&gt;Jhon&lt;/span&gt;
visits a webpage &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;www.example.com&lt;/b&gt;&lt;/span&gt;
and then he tries to login to his account in that website. After
entering his credentials and pressing the login button, the server
receives a login request with username / email and password from
Jhon.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
Then server performs verification of
whether that credentials are valid or not. If it is found to be
valid, then a &lt;a href=&quot;https://en.wikipedia.org/wiki/HTTP_cookie&quot; target=&quot;_blank&quot;&gt;cookie&lt;/a&gt; is created on the
server-end along with a unique session id that is generated by the
server itself. That cookie is then sent by the server to the browser
that sent the request. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
Next time, if the user tries to send
another request to the server, then that request is sent to server
with the session id, then server is able to process that request
successfully. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;b&gt;Why
a cookie needs to be created ?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
Server needs to send the cookie to the
browser in order to identify whether the request is coming from the
same user or not. This happens, as HTTP requests are stateless in
nature, that means each individual request is executed independently.
Server has no idea about previous requests status, so it needs a way
to keep track of the commands that were executed before; that&#39;s why
to identify if the request is coming from the same user, it stores a
unique session id in cookie.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
So, every time the browser sends a
request to a website it automatically attaches a cookie that is
stored in the browser for that website. Even if the request to the
website is made by another website that is loaded in the user&#39;s
browser.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;How&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Cross Site Request Forgery&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;Actually
Works?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
Now, you&#39;ve understood the basics
behind sessions and cookies, let&#39;s discuss how csrf actually works.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
The attacker creates a malicious
website and then he or she uses social engineering tricks to lure the
victim to visit that website. The trick could involve sending the
victim an email stating that he or she won a lottery and claim the
prize by clicking on a link.  
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
When victim clicks that link, the
script of that malicious gets executed and it can perform unwanted
actions to the website in which he or she is currently authenticated.
All of these incidents could happen without the knowledge of the
user.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Example on cross site
request forgery&lt;/span&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
To see CSRF in action, at first we need
to create a new folder &quot;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;hacker&lt;/span&gt;&lt;/b&gt;&quot; under the root folder of
our project directory. Also, we need to create some users manually in
our users table. For example, I have created a user &quot;&lt;span style=&quot;color: magenta;&quot;&gt;&lt;b&gt;dummyuser4&lt;/b&gt;&lt;/span&gt;&quot;. Then we need to create 3 files (e.g, config.php, index.php, delete_user.php) in &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;hacker&lt;/span&gt;&lt;/b&gt; folder.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhteGLCgnLKUFBcblBf-UXKeCcpl0z101Qu4AluecQsupQ64hlEkqJx4vsIgJpv6xTrotIdqjiniUjDZ1F1ceJfaWD7ZP9A9J6SDafhZs5kTUwF01aqia_Y5ZUhiS4QIkhf_vXpKVJcPEyv/s1600/CSRF+Config+Page+Codes.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;CSRF Config Page Codes&quot; border=&quot;0&quot; data-original-height=&quot;307&quot; data-original-width=&quot;586&quot; height=&quot;334&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhteGLCgnLKUFBcblBf-UXKeCcpl0z101Qu4AluecQsupQ64hlEkqJx4vsIgJpv6xTrotIdqjiniUjDZ1F1ceJfaWD7ZP9A9J6SDafhZs5kTUwF01aqia_Y5ZUhiS4QIkhf_vXpKVJcPEyv/s640/CSRF+Config+Page+Codes.png&quot; title=&quot;CSRF Config Page Codes&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;CSRF Config Page Codes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWKJurv3aCDXy3vggqy-QxcVoNub2EoqGmDesqcpCHxRQ2ZHlbTpE8K_82A3fDmmTdUe9npo1tWUXiLH-y8XoRSA3-jG3WQ8fafZgvaIqgLw2bh6gb0RCrTc-az3shyphenhyphenQTIDQ6nUR-vL-Bt/s1600/CSRF+Index+Page+Codes.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;CSRF Index Page Codes&quot; border=&quot;0&quot; data-original-height=&quot;650&quot; data-original-width=&quot;690&quot; height=&quot;602&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWKJurv3aCDXy3vggqy-QxcVoNub2EoqGmDesqcpCHxRQ2ZHlbTpE8K_82A3fDmmTdUe9npo1tWUXiLH-y8XoRSA3-jG3WQ8fafZgvaIqgLw2bh6gb0RCrTc-az3shyphenhyphenQTIDQ6nUR-vL-Bt/s640/CSRF+Index+Page+Codes.png&quot; title=&quot;CSRF Index Page Codes&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;CSRF Index Page Codes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9bnGnyMWibx5YFo9L5oTlxAA-6fa_97ILmMo7P_YF0ZS5_BIr4IcWb16ZUsUMyazJ4WAXkpvx5flJYKvg6g6yS5Dg_fh7j1QfVI09adqhuPvbo4zlUrDSzp1Z9HP3PiS5m-0CwPYImwNf/s1600/CSRF+Delete+Page+Codes.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;CSRF Delete Page Codes&quot; border=&quot;0&quot; data-original-height=&quot;363&quot; data-original-width=&quot;632&quot; height=&quot;366&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9bnGnyMWibx5YFo9L5oTlxAA-6fa_97ILmMo7P_YF0ZS5_BIr4IcWb16ZUsUMyazJ4WAXkpvx5flJYKvg6g6yS5Dg_fh7j1QfVI09adqhuPvbo4zlUrDSzp1Z9HP3PiS5m-0CwPYImwNf/s640/CSRF+Delete+Page+Codes.png&quot; title=&quot;CSRF Delete Page Codes&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;CSRF Delete Page Codes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
We also made some changes in the dashboard page, the added codes for the dashboard page is shown below.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhecxNmepevaDPrqslt0UlXunS7d8N3c3CWoLj5RidRIF5w93qZBYpmr9yxhDOiI1S-ajxXDnoAQL3kPjoKfDQa9ZDqbl5qmN3w6LThp_G1_FgdoKzojmZjuFbc34mAvL2LrvAMl-vDGoxs/s1600/Dashboard+Page+CSRF+Attack.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Dashboard Page CSRF Attack URL&quot; border=&quot;0&quot; data-original-height=&quot;381&quot; data-original-width=&quot;1064&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhecxNmepevaDPrqslt0UlXunS7d8N3c3CWoLj5RidRIF5w93qZBYpmr9yxhDOiI1S-ajxXDnoAQL3kPjoKfDQa9ZDqbl5qmN3w6LThp_G1_FgdoKzojmZjuFbc34mAvL2LrvAMl-vDGoxs/s640/Dashboard+Page+CSRF+Attack.png&quot; title=&quot;Dashboard Page CSRF Attack URL&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Dashboard Page CSRF Attack URL&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Explanation
of What We Did&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
In index.php page that is created
inside hacker folder, the attacker uses jQuery library to initiate an
Ajax call that will run the &lt;span style=&quot;color: #b4a7d6;&quot;&gt;&lt;b&gt;delete_user php&lt;/b&gt;&lt;/span&gt; script. After
successfully executing the Ajax request, it displays &#39;success&#39;
message in the browser&#39;s console window.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
The &lt;span style=&quot;color: #b4a7d6;&quot;&gt;&lt;b&gt;delete_user.php&lt;/b&gt;&lt;/span&gt; page get the name
of the user from the current active session. Then it executes the
delete query to delete that particular user from the &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;users&lt;/span&gt;&lt;/b&gt;
table.&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
We added an image in the dashboard page, that has a link attached to the index.php script file. So, when the victim will click on the image to claim his or her lottery prize, the CSRF would take place, in which the attack will delete a user named &quot;&lt;b style=&quot;color: magenta;&quot;&gt;dummyuser4&lt;/b&gt;&lt;b&gt;&quot;.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPo7HehMzCOZPw6E6jFNFpvZyYBhvYwrjQ5TtqrjMv3p9kphVq1VA-pZMQuyAfGv3VrU0pu4Z-iQ_vslG8cdiBp-XxdXxzZyq3ph8UuyGE5xDmpMcN5dhrtQmGaVIWpbTabTQGn1MLjsQ/s1600/Users+Table+Before+CSRF+Attack.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Users Table Before CSRF Attack&quot; border=&quot;0&quot; data-original-height=&quot;236&quot; data-original-width=&quot;365&quot; height=&quot;412&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAPo7HehMzCOZPw6E6jFNFpvZyYBhvYwrjQ5TtqrjMv3p9kphVq1VA-pZMQuyAfGv3VrU0pu4Z-iQ_vslG8cdiBp-XxdXxzZyq3ph8UuyGE5xDmpMcN5dhrtQmGaVIWpbTabTQGn1MLjsQ/s640/Users+Table+Before+CSRF+Attack.png&quot; title=&quot;Users Table Before CSRF Attack&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Users Table Before CSRF Attack&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmYODSqRXWTjEeekpjto-yyaD4ta0Tv4-UEcuF8MQU77FgfuYx5b5csEmgBzDs0D9nO7EdMxicOgT6DF6nzHxSl9pZfTeiiNq6wAjF-wxGQ2xxFOG6VQgQaN9fdBAfUOdgk4013lP6oonu/s1600/Users+Table+After+CSRF+Attack.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Users Table After CSRF Attack&quot; border=&quot;0&quot; data-original-height=&quot;209&quot; data-original-width=&quot;366&quot; height=&quot;364&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmYODSqRXWTjEeekpjto-yyaD4ta0Tv4-UEcuF8MQU77FgfuYx5b5csEmgBzDs0D9nO7EdMxicOgT6DF6nzHxSl9pZfTeiiNq6wAjF-wxGQ2xxFOG6VQgQaN9fdBAfUOdgk4013lP6oonu/s640/Users+Table+After+CSRF+Attack.png&quot; title=&quot;Users Table After CSRF Attack&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Users Table After CSRF Attack&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Preventing&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Cross Site Request Forgery&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&amp;nbsp;Attack&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;b&gt;Implementing
Unique CSRF Token&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
The best way to prevent this attack is
to use a unique token that will be auto generated by the server. The
token must be generated in a random way and it should contain
cryptographic value for each new request made to the server. The
token should be stored in the user&#39;s session so that the server could
be able to verify it.&lt;br /&gt;
&lt;br /&gt;
Following youtube video explains this approach in depth.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/8MksjpfDvRw&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: 11pt;&quot;&gt;&lt;b&gt;Protecting
Against XSS&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
If the web application is vulnerable to
cross site scripting(link to my own article) (also known as xss),
attack then the attacker can easily get the csrf token from the html
page. So, in order to prevent csrf attack, we also need to make sure
that no xss vulnerability exists in the web application. 
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
Download the entire project by clicking below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://drive.google.com/file/d/1IqywdUMdDCVJ6McDRZRjGwgLvJJZv-72/view?usp=sharing&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYNQPH7Nz7oSSTw5WIFyDfQtchmwdX2P7-12NtEbUDBl1z_xVbI91aw65zY4XTm0cGtGsH4cKhNqxAy9-lvrHydd1pygAK3rFnh9caWVaKydMqJ2bYyPlRRtipiM7OtsUDkOM0smUy152c/s320/download_button.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Final Words&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
If
you find this post about &lt;b&gt;Cross Site Request Forgery&lt;/b&gt; helpful, please share it among the others. Thank
you!&amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/cross-site-request-forgery.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMC1D1TBeHInTTzA2p5sRLGytTPvm1KX51nSm2m9GAOa7cRSo40e4H7c7h1wukEIUKBqgpTaOI-38eMQQ-ET8qt5ilV_IbGn7Mz8mnwRLdPWRhd_tmiSspe7jUXSzoWwzljMojayWkwLnL/s72-c/Cross+Site+Request+Forgery.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-7367979679358563273</guid><pubDate>Wed, 03 Jul 2019 15:53:00 +0000</pubDate><atom:updated>2023-03-08T16:10:24.584+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>Step By Step Guide On Cross Site Scripting</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This post is the final part of the &lt;b&gt;cross site scripting&lt;/b&gt; series. If you have missed the first part for some reason, you can read it &lt;a href=&quot;https://www.devhelperworld.in/2019/07/cross-site-scripting.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
Important Note&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Please note that, all the information provided in this article is solely meant for educational purposes only.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
What We Will Be Creating&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We will create two pages; a post creation and post listing page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Screen shot of post listing page is shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ6cNtdomgc56FnjX6tdVihimA_SX8bUgS37xQ-2uKAwAJfR_IhQn8UQ4h_wReEXuKVerN0-q2pFGk50AkFD8owO0dZFIod4_YQ9yHQOBDqR4Hw-uNWf2wR-z_c2T91v9gmEaOv2lXgSv5/s1600/post_listing.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Post Listing Page&quot; border=&quot;0&quot; data-original-height=&quot;720&quot; data-original-width=&quot;1342&quot; height=&quot;342&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ6cNtdomgc56FnjX6tdVihimA_SX8bUgS37xQ-2uKAwAJfR_IhQn8UQ4h_wReEXuKVerN0-q2pFGk50AkFD8owO0dZFIod4_YQ9yHQOBDqR4Hw-uNWf2wR-z_c2T91v9gmEaOv2lXgSv5/s640/post_listing.png&quot; title=&quot;Post Listing Page&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;Screen shot of post creation page is shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH-SF4EsP8OC7AvF-MgP9ARAgBLMo5XchoZgEDe5njlJkFHZAQVPJZgewmdrFJVE94mlGOexaelMJQrSt2EeeqCcr13BZbBzf8lSpUcynkJnd0L_a2lesBJriVCZgAkQ3cFa5AepDPQ1lr/s1600/post_creation.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Post Creation Page&quot; border=&quot;0&quot; data-original-height=&quot;722&quot; data-original-width=&quot;1341&quot; height=&quot;344&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH-SF4EsP8OC7AvF-MgP9ARAgBLMo5XchoZgEDe5njlJkFHZAQVPJZgewmdrFJVE94mlGOexaelMJQrSt2EeeqCcr13BZbBzf8lSpUcynkJnd0L_a2lesBJriVCZgAkQ3cFa5AepDPQ1lr/s640/post_creation.png&quot; title=&quot;Post Creation Page&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Post Creation Page&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In order to follow along with this article, you need to create a post table in your database using php myadmin.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The table structure for the post table is as follows.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6cKFr03onBgC-0oSHxTWubnSUusxJYDVuhbZWVfE43-VJAsDKjxSnNixfGWtV1ugOnmBN0SGJt_52hbfCV6is4LJEr8ujkV9lAIptbFDgtaGw2JJLFlV8e0xn_l24ac96-RZx7qtPOr3h/s1600/posts_table_structure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Post Table Structure&quot; border=&quot;0&quot; data-original-height=&quot;216&quot; data-original-width=&quot;1065&quot; height=&quot;128&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6cKFr03onBgC-0oSHxTWubnSUusxJYDVuhbZWVfE43-VJAsDKjxSnNixfGWtV1ugOnmBN0SGJt_52hbfCV6is4LJEr8ujkV9lAIptbFDgtaGw2JJLFlV8e0xn_l24ac96-RZx7qtPOr3h/s640/posts_table_structure.png&quot; title=&quot;Post Table Structure&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Post Table Structure&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Following screen shot is the code for the db.php file that contains database connectivity codes.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioQz2Y8mBfJFGZeqxmX2uBTh2Zv_lI2Oxo4f8TIPm47S46-yVQlaq4ZXhL0AL9MhkaILnYed4cn6HWDB5eJT9mF4b5xKrn8spkCl41BfjuJ1BzOS0sND8P1txfKFOwWhBSBsFjglLusHH1/s1600/xss_db_connectivity.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Cross Site Scripting Database Connectivity Codes&quot; border=&quot;0&quot; data-original-height=&quot;171&quot; data-original-width=&quot;538&quot; height=&quot;202&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioQz2Y8mBfJFGZeqxmX2uBTh2Zv_lI2Oxo4f8TIPm47S46-yVQlaq4ZXhL0AL9MhkaILnYed4cn6HWDB5eJT9mF4b5xKrn8spkCl41BfjuJ1BzOS0sND8P1txfKFOwWhBSBsFjglLusHH1/s640/xss_db_connectivity.png&quot; title=&quot;Cross Site Scripting Database Connectivity Codes&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Database Connectivity Codes&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Download the entire project by clicking the download button below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://www.devhelperworld.in/p/download-link-page.html&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Download Button&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggNIKtQcy0dtSmUa_EdtuStTL7oJAvZffCoRvEc0MHqov7dk0SS9V4AQoqvSOXJoIRns6VB-wx5oyQhO-r0gKGhoavaB86FmjZemLkTK6IK2Va5PDNlOnocTLLTbRs2VBLMaOeBpQfNOtQ/s320/download_button.png&quot; title=&quot;Download Button&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
Explanation of posts.php:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the posts.php file, the post title and description is saved into
post table. Before saving post, we make sure that our application is
safe from sql injection. In order to do so, we used
mysqli_real_escape_string() function. If you don&#39;t know anything
about sql injection, you can read it &lt;a href=&quot;https://www.devhelperworld.in/2019/06/sql-injection.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
Exploiting The Application By Stored Cross Site Scripting&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We finished adding post creation functionality for this
application. Let&#39;s see how to exploit this application so that when
anyone visits this page, his or her session cookie will be stolen and
send to the attacker.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the screen shot below, attacker injects the javascript code in
the comment box, that executes a php code via AJAX call.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4l1tmZxGlhUzYQaxh9of9o5Gpf2xOnJF7IM51tsZ5X6LeQiTheKH3ZQv-ApuvWr9i_7RxLtTCTmyHvXuu-ltlaQ4uwWqjRGxKqwh6uqSoU2d5nE-_L_fvLrjjYlAv6XXS4k2VmUlp5qjd/s1600/injected_xss_code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Injected Cross Site Scripting Codes&quot; border=&quot;0&quot; data-original-height=&quot;708&quot; data-original-width=&quot;1340&quot; height=&quot;338&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4l1tmZxGlhUzYQaxh9of9o5Gpf2xOnJF7IM51tsZ5X6LeQiTheKH3ZQv-ApuvWr9i_7RxLtTCTmyHvXuu-ltlaQ4uwWqjRGxKqwh6uqSoU2d5nE-_L_fvLrjjYlAv6XXS4k2VmUlp5qjd/s640/injected_xss_code.png&quot; title=&quot;Injected Cross Site Scripting Codes&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Injected Cross Site Scripting Codes&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We can see from the above screen shot that, after adding jquery cdn link, reference to a file known as &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;evil.js&lt;/b&gt;&lt;/span&gt; is added. For getting this example to work successfully, you need to create a file &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;evil.js&lt;/span&gt;&lt;/b&gt; in the js folder of the root directory of the current project.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;


&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
Explanation of evil.js:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;evil.js&lt;/span&gt;&lt;/b&gt; file collects cookies that is stored in the browser,
and then it sends that in &lt;span style=&quot;color: purple;&quot;&gt;getCookiedata.php&lt;/span&gt;
file.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;


&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Explanation of getCookiedata.php:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Stolen cookie information is stored in &quot;&lt;span style=&quot;color: blue;&quot;&gt;cookie_data.txt&lt;/span&gt;&quot;
file. If the code executes for the first time, then that file will be
created in root directory of the application. If already this file
exists, then new content will be appended to the file. 
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;


&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To make sure that you understand the stored xss attack, we stored
the &lt;span style=&quot;color: blue;&quot;&gt;cookie_data.txt&lt;/span&gt; file in the root of the application. But,
generally, attacker stores the information to his or her own server.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Getting Session Cookie Value&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After attacker injects the javascript
codes, nothing is displayed as post description in the post listing page as we can see
from the screen shot below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkdqe2PspbqxpMlgSxRgB_37H9Qr6E2BzHD_n_jUgI5bJK2H-DKpzVBtynTq7OysewDTo0QhKEfG6DuU4BINnQeRy2bWgpsG71RCbOFbDoXnVaSM6_dYO88ZQ1wzPFiwDfNUmbhV-vxdsi/s1600/after_xss_injection.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;After XSS Injection&quot; border=&quot;0&quot; data-original-height=&quot;712&quot; data-original-width=&quot;1220&quot; height=&quot;372&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkdqe2PspbqxpMlgSxRgB_37H9Qr6E2BzHD_n_jUgI5bJK2H-DKpzVBtynTq7OysewDTo0QhKEfG6DuU4BINnQeRy2bWgpsG71RCbOFbDoXnVaSM6_dYO88ZQ1wzPFiwDfNUmbhV-vxdsi/s640/after_xss_injection.png&quot; title=&quot;After XSS Injection&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After XSS Injection&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;But, if we open the &quot;&lt;span style=&quot;color: blue;&quot;&gt;cookie_data.txt&lt;/span&gt;&quot;
file, we can see the session cookie content is present there!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHx2cVyMk2OJ496IrTSXCapCGCdtcBJcJLMNFQc8HHsCQpjnCDfauVHo9BWBhFFS1qdalN0ja_wrgbyy1yuFJCgrdrEz0PLkwPXpl_mAecNS_ySYXOLccyM3l0Ga28V5TytniRUQw7a_hO/s1600/session_cookie_revealed.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Session Cookie Revealed&quot; border=&quot;0&quot; data-original-height=&quot;219&quot; data-original-width=&quot;681&quot; height=&quot;204&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHx2cVyMk2OJ496IrTSXCapCGCdtcBJcJLMNFQc8HHsCQpjnCDfauVHo9BWBhFFS1qdalN0ja_wrgbyy1yuFJCgrdrEz0PLkwPXpl_mAecNS_ySYXOLccyM3l0Ga28V5TytniRUQw7a_hO/s640/session_cookie_revealed.png&quot; title=&quot;Session Cookie Revealed&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Session Cookie Revealed&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Preventing Cross-Site Scripting Attack&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We saw, how an attacker can make
use of &lt;b&gt;xss&lt;/b&gt;
to steal session cookie in previous screen shot. Now, we will stop
the attacker from doing that.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Make the changes in &quot;&lt;span style=&quot;color: purple;&quot;&gt;save_post.php&lt;/span&gt;&quot;
file that are highlighted in red as shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvS7XyXUtMv-5WinclkkVuyPdzshhQ7owOtYPQIqaAn8RdEfZ1K_jYMxidx1TENEZ-RzbotwAr-VNht9Q8q9oq5sie19Xbz0JcEmt-iZKd-XS9dgkc5tIBFyj0jxJZxCxaQS-27y5yS2ZM/s1600/prevent_xss.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Preventing XSS&quot; border=&quot;0&quot; data-original-height=&quot;413&quot; data-original-width=&quot;725&quot; height=&quot;364&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvS7XyXUtMv-5WinclkkVuyPdzshhQ7owOtYPQIqaAn8RdEfZ1K_jYMxidx1TENEZ-RzbotwAr-VNht9Q8q9oq5sie19Xbz0JcEmt-iZKd-XS9dgkc5tIBFyj0jxJZxCxaQS-27y5yS2ZM/s640/prevent_xss.png&quot; title=&quot;Preventing XSS&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Preventing XSS&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Explanation:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We used, &lt;a href=&quot;https://www.php.net/manual/en/function.htmlspecialchars.php&quot; target=&quot;_blank&quot;&gt;htmlspecialchars()&lt;/a&gt; function, that will convert some special characters to HTML
entities so that xss will no longer work. For example, &quot;&amp;gt;&quot;
will be converted to &quot;&amp;amp;gt;&quot;. 
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Now, if we clear the contents of
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;cookie_data.txt&lt;/span&gt;&lt;/b&gt;
file, previous post record that stores the injected javascript code
in post table and then again try to repeat what we did earlier, then
see what will happen!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After pressing Save Post button, if we
open the post table, we will see something similar to the screen shot
below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWp2NwGKnL-8Od4Rpw751gnaJuziI7CXS_5CW1KE13Lug2RKstSkEG1VGYyZLvJ-cfjg1dDNC-bC2sAIFdvVixsmCpwK2VwAzH5JVnnnLZSzA49u_bIS-8i9IfhSwH_37ldmMKxSgRPLgV/s1600/protection_xss_db.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;img alt=&quot;Post table data after xss protection&quot; border=&quot;0&quot; data-original-height=&quot;190&quot; data-original-width=&quot;701&quot; height=&quot;172&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWp2NwGKnL-8Od4Rpw751gnaJuziI7CXS_5CW1KE13Lug2RKstSkEG1VGYyZLvJ-cfjg1dDNC-bC2sAIFdvVixsmCpwK2VwAzH5JVnnnLZSzA49u_bIS-8i9IfhSwH_37ldmMKxSgRPLgV/s640/protection_xss_db.png&quot; title=&quot;Post table data after xss protection&quot; width=&quot;640&quot; /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Post Table Data After XSS Protection&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;Now, if we open the &quot;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;cookie_data.txt&lt;/b&gt;&lt;/span&gt;&quot;
file, we will no longer see any content inside of it. It is
completely empty.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Final Words&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you find this article helpful, please share
it among others.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/cross-site-scripting-example.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJ6cNtdomgc56FnjX6tdVihimA_SX8bUgS37xQ-2uKAwAJfR_IhQn8UQ4h_wReEXuKVerN0-q2pFGk50AkFD8owO0dZFIod4_YQ9yHQOBDqR4Hw-uNWf2wR-z_c2T91v9gmEaOv2lXgSv5/s72-c/post_listing.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-5023173262263622503</guid><pubDate>Mon, 01 Jul 2019 15:18:00 +0000</pubDate><atom:updated>2023-03-08T16:10:28.293+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>Never Mess With Cross Site Scripting And Here&#39;is The Reason Why</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivhcCd3MWGEKsJUxzkeWe2cYS2XMflFFXN0mEV9Zu-wPUseM9_PGJV_0pplYbvq25E5CqkM3DfjZbYleKuma0sjUYhdXvYGuW-zOHRtpInBCTDW8UPvSxSNEh8S_eZ9prM3A1YT2hSea6e/s1600/xss.jpg&quot; imageanchor=&quot;1&quot;&gt;&lt;img alt=&quot;Cross Site Scripting&quot; border=&quot;0&quot; data-original-height=&quot;575&quot; data-original-width=&quot;1023&quot; height=&quot;358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivhcCd3MWGEKsJUxzkeWe2cYS2XMflFFXN0mEV9Zu-wPUseM9_PGJV_0pplYbvq25E5CqkM3DfjZbYleKuma0sjUYhdXvYGuW-zOHRtpInBCTDW8UPvSxSNEh8S_eZ9prM3A1YT2hSea6e/s640/xss.jpg&quot; title=&quot;Cross Site Scripting&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_4&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_5&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_6&quot;&gt;&lt;/a&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;In
a &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;Cross-site
Scripting&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
attack, also known as &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;xss&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;,
client-side code is injected into the output of&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;a
web&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;page,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;in
form of a&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;html&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;attribute,
and&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;executed&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;within
the&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;user’s
browser. The impact of&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;successful&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;exploitation
varies.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Why
do I care about Cross-site Scripting?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_16&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_31&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_41&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_51&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_61&quot;&gt;&lt;/a&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt; Cross-Site
Scripting&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
vulnerabilities&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;may
be&amp;nbsp;utilized by&amp;nbsp;an&amp;nbsp;offender&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;to
accomplish&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;an
extended&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;list
of potential&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;wicked
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;goals,
including:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Steal your session&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;identifier&amp;nbsp;so that they&amp;nbsp;will&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;impersonate you and access&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;the online&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;application.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Redirect you to a phishing page that gathers sensitive&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;data&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Install malware on your&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;pc&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;(usually&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;needs&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;a zero day vulnerability for your browser and OS).&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Perform tasks on your behalf (i.e.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;produce&amp;nbsp;a brand new&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;administrator account with the attacker&#39;s credentials).&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/span&gt;&lt;/ol&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;h4 style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: verdana, sans-serif;&quot;&gt;Different Types Of Cross-site Scripting Explained&lt;/span&gt;&lt;/h4&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_14&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_15&quot;&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;There are 3 types of &lt;b&gt;xss &lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;these
are as follows...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;h3 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Reflected
Cross-Site Scripting:&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-size: small; font-weight: normal;&quot;&gt;
&lt;/span&gt;
&lt;/span&gt;&lt;/h3&gt;
&lt;ul&gt;
 &lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5r_OIo7mE6H_24x4K1MwEsfUY-T7S2xzFIguWCfOuEHf9LgcC5RL9i1Ep72GfI2I9SewrUGprlMHwaNg4Dl0w2TcX8BP2LJB8odMEkbIWwvCySYSboa7Ab3bCig0OwnJ3914-poNhmWy9/s1600/reflected_xss.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Reflected Cross-Site Scripting&quot; border=&quot;0&quot; data-original-height=&quot;1600&quot; data-original-width=&quot;1061&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5r_OIo7mE6H_24x4K1MwEsfUY-T7S2xzFIguWCfOuEHf9LgcC5RL9i1Ep72GfI2I9SewrUGprlMHwaNg4Dl0w2TcX8BP2LJB8odMEkbIWwvCySYSboa7Ab3bCig0OwnJ3914-poNhmWy9/s640/reflected_xss.jpg&quot; title=&quot;Reflected Cross-Site Scripting&quot; width=&quot;424&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div class=&quot;graf graf--p&quot; name=&quot;4c59&quot;&gt;
Image source: pexels&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_42&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_52&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_62&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_81&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_91&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_101&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_111&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_131&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_142&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_152&quot;&gt;&lt;/a&gt;
 &lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;In
 this type of attack, a vulnerable&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;page&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;will
 be&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;used
 to&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;execute&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;impulsive&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;code.
 This type of &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;xss&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;doesn&#39;t&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;persist
 the attack code across multiple requests.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Since&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;an&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;attacker&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;has
 to&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;send
 a user to a specially crafted&amp;nbsp;link&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;for
 the code to run, reflective &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;XSS&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;sometimes&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;needs&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;some
 &lt;a href=&quot;https://en.wikipedia.org/wiki/Social_engineering_(security)&quot; target=&quot;_blank&quot;&gt;social engineering&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;to
 execute the attack successfully&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
 &lt;/span&gt;
 &lt;/span&gt;&lt;/div&gt;
&lt;/ul&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;h3 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt; Real world
scenario of reflected cross-site scripting: &lt;/span&gt;
&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; Let&#39;s
assume, Sam is an attacker, he found a refected &lt;/span&gt;&lt;b&gt;xss&lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; vulnerability in
&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;www.site.com&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;. Jhon is
a user of this website, Sam sends a fake email  to Jhon that he is
the lucky winner of an Iphone and to claim it he needs to click on
the link provided in the email.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Jhon clicks the link while logged
into &lt;/span&gt;www.site.com&lt;i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;. &lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;The
script gets executed in Jhon&#39;s browser, it steals Jhon&#39;s session
cookies associated to &lt;/span&gt;&lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;www.site.com&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
and sends to Sam. &lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; Using
the session cookie, Sam can easily access Jhon&#39;s personal information
and other data such as credit card or debit card data by compromising
Jhon&#39;s account.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;Stored &lt;b&gt;xss&lt;/b&gt;:&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqgdsgI761yhCHtLBPBga2YSr8uoFxx8VY6ZpB7x4SkvDZpbFQ29j_Jrytv83tclxrRKagSVtbmn6XOwWKGdEyo55rjNDVE5dcm9BfH3DK2wYeD4aPei9AhX3vqv8I0TaYI_EqzQtuJSOH/s1600/stored_xss.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Stored XSS&quot; border=&quot;0&quot; data-original-height=&quot;853&quot; data-original-width=&quot;1280&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqgdsgI761yhCHtLBPBga2YSr8uoFxx8VY6ZpB7x4SkvDZpbFQ29j_Jrytv83tclxrRKagSVtbmn6XOwWKGdEyo55rjNDVE5dcm9BfH3DK2wYeD4aPei9AhX3vqv8I0TaYI_EqzQtuJSOH/s640/stored_xss.jpg&quot; title=&quot;Stored XSS&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Image source: pexels&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; In
this type attack, malicious data supplied by the attacker will be
stored in the server. It is more dangerous compared to reflected &lt;/span&gt;&lt;b&gt;xss&lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
for following reasons.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;First, a&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;stored&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&lt;b&gt;xss&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;
 attack&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;will
 be&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;automatic&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;.
 A script&amp;nbsp; that visits thousands&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;of
 websites&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;,
 can exploit a vulnerability on&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;every&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;web
 site&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;and
 drops a&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;stored&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333; font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;xss&lt;/b&gt; payload.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Second,
 victims&amp;nbsp;don’t&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;need
 to&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;take
 any action&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;apart
 from&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;visiting
 the affected&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;web
 site&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;.
 Anyone that visits the affected page on&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;the
 site&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;will&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;become
 a victim&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;as
 a result of&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;the&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;stored&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;malicious
 code.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;It happens beacuse the script&amp;nbsp;will&amp;nbsp;load in their
 browser The victims&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;don&#39;t&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;
 need&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;
 to&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;take&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;an
 extra&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;action.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #333333; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
         &lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;Real
world scenario of stored xss:&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; Suppose, &lt;/span&gt;&lt;i&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;www.techforum.com&lt;/span&gt;&lt;/i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
is a forum having thousands of users, users can post on different
technical topics, and they can also comment on each post. Sam decides
to get user credentials by exploiting the commenting functionality.
He, writes few lines as comment and then crafts a malicious link that
acts as a read more link. &lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; When users of the forum reads
few lines of his comments, and curious to read the rest of it, they
will click on &lt;/span&gt;&lt;span style=&quot;color: #ff3300;&quot;&gt;&lt;b&gt;read more&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
link. That link will activate a javascript file, that will steal
users session cookies.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;DOM
Based &lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;b&gt;xss&lt;/b&gt;&lt;/span&gt;:&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZzeZuLqlf6GLI5bdSs5Vq8E0U9_eRvaZcgFtWO6kGCG1uPji45fZ1l-etRgS_mLnT2elyjKYJRsNuaijVx2CSlJ9Mui9xxA0g3iLxkMKIF5HRe3LDdufImEfdqAq0seKsbuEDw6rw8CcY/s1600/dom_xss.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;DOM Based XSS&quot; border=&quot;0&quot; data-original-height=&quot;853&quot; data-original-width=&quot;1280&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZzeZuLqlf6GLI5bdSs5Vq8E0U9_eRvaZcgFtWO6kGCG1uPji45fZ1l-etRgS_mLnT2elyjKYJRsNuaijVx2CSlJ9Mui9xxA0g3iLxkMKIF5HRe3LDdufImEfdqAq0seKsbuEDw6rw8CcY/s640/dom_xss.jpg&quot; title=&quot;DOM Based XSS&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Image source: pixabay&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; This
type of attack generally involves around the DOM(Document Object
Model). In other types of attacks, infected code comes from the
server-end to the client-end. But, in this type of attack, javascript
code is used to manipulate the DOM. &lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;h3 class=&quot;western&quot; style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt; How DOM Based
xss is possible ?&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_110&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_22&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_33&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_43&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_54&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_72&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_92&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_102&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://www.blogger.com/null&quot; name=&quot;tip_122&quot;&gt;&lt;/a&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;This
is&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;possible&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;partially&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;as
a result of&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;advanced&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;j&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;avaScript-based
applications take bits&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;of
information&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;from&amp;nbsp;different&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;places
and&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;process&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;them.&amp;nbsp;G&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;enerally&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;that&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;process&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;ends
up in&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;the
creation of DOM objects or direct JavaScript&amp;nbsp;execution&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;within
the&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;browser.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;
 &lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; DOM
&lt;/span&gt;&lt;b&gt;xss&lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; comprises of two facts: &lt;span style=&quot;color: #0b5394;&quot;&gt;Source&lt;/span&gt; and &lt;span style=&quot;color: #741b47;&quot;&gt;Sink&lt;/span&gt;. &lt;span style=&quot;color: #0b5394;&quot;&gt;Source&lt;/span&gt; is something that
contains user input. &lt;span style=&quot;color: #741b47;&quot;&gt;Sink&lt;/span&gt; is known as the place where user input gets
executed by the browser. &lt;/span&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt; Conclusion:&lt;/span&gt;&lt;/h3&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; In
this article, I discussed in brief why you should not neglect &lt;/span&gt;&lt;b&gt;cross
site scripting&lt;/b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;. I hope, you will find this article helpful for you.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/07/cross-site-scripting.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivhcCd3MWGEKsJUxzkeWe2cYS2XMflFFXN0mEV9Zu-wPUseM9_PGJV_0pplYbvq25E5CqkM3DfjZbYleKuma0sjUYhdXvYGuW-zOHRtpInBCTDW8UPvSxSNEh8S_eZ9prM3A1YT2hSea6e/s72-c/xss.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-4505982813944341086</guid><pubDate>Fri, 21 Jun 2019 16:36:00 +0000</pubDate><atom:updated>2023-03-08T16:10:30.977+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>Command Injection In A Nutshell</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;/h2&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5cYEqZhgRSsS5zHzN5XgkS6j5zfUj4-jSG6myEGcJRAyxRWzI5bjwNx8aNGRjffkBfMjnhcI83Dwb-w15RpPgxF-vubY9DYvIJxVvy-Ac0s1HYdLuQS5xF2fv63hrXRlITV2jAhSX9Ysa/s1600/command-injection-intro-pic.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;command-injection-intro-pic&quot; border=&quot;0&quot; data-original-height=&quot;533&quot; data-original-width=&quot;800&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5cYEqZhgRSsS5zHzN5XgkS6j5zfUj4-jSG6myEGcJRAyxRWzI5bjwNx8aNGRjffkBfMjnhcI83Dwb-w15RpPgxF-vubY9DYvIJxVvy-Ac0s1HYdLuQS5xF2fv63hrXRlITV2jAhSX9Ysa/s640/command-injection-intro-pic.jpg&quot; title=&quot;command-injection-intro-pic&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Command injection&lt;/b&gt; is a technique used by the attacker to attack a server via it&#39;s operating system commands. This type of attack took place when the web application is utilizing system commands to provide&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;some sort of&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;functionality to a web application.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;What Can Be Done By Using it ?&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This type of attack can lead to massive damage as the attacker is able to take control of the server&#39;s operating system by executing it&#39;s system commands. Attacker can view internal configuration files of the server, can modify or even delete data, or even worse can setup a backdoor that can access server resources remotely.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Important Note&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;Please note that, all the information provided in this post is solely meant for educational purposes only.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;Command Injection : In Action&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;To explain this attack, at first we will create an application, which will get the IP (Internet Protocol) address for a particular DNS (&lt;a href=&quot;https://en.wikipedia.org/wiki/Domain_Name_System&quot; target=&quot;_blank&quot;&gt;Domain Name System&lt;/a&gt;). As, we are using windows operating system to locally host our application, so we need to enter only windows shell commands to launch this attack. If the application is hosted on a linux server, then we are required to use linux shell commands.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Download the entire project by clicking below button&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://www.devhelperworld.in/p/download-link-page.html&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Download Button&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggNIKtQcy0dtSmUa_EdtuStTL7oJAvZffCoRvEc0MHqov7dk0SS9V4AQoqvSOXJoIRns6VB-wx5oyQhO-r0gKGhoavaB86FmjZemLkTK6IK2Va5PDNlOnocTLLTbRs2VBLMaOeBpQfNOtQ/s320/download_button.png&quot; title=&quot;Download Button&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: red; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;Getting List Of All Directories Of Application&#39;s Root Location&lt;/span&gt;&lt;/h4&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUnIKM2JjsIZZFvdFyFMrR48LxkNwh-ZkSqxpDkVXbYuMbmtVlQ2pYQiCYBiWQbUvBKo40SoEGky4MvTwA80EXK08bGDdoS4EetS4cbOfRn83PTlfvZ97-DElXpjrS5ws47w8NXSdkMUjt/s1600/getting_all_directories.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;644&quot; data-original-width=&quot;1150&quot; height=&quot;355&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUnIKM2JjsIZZFvdFyFMrR48LxkNwh-ZkSqxpDkVXbYuMbmtVlQ2pYQiCYBiWQbUvBKo40SoEGky4MvTwA80EXK08bGDdoS4EetS4cbOfRn83PTlfvZ97-DElXpjrS5ws47w8NXSdkMUjt/s640/getting_all_directories.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Getting List Of All Directories Of Application&#39;s Root Location&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;Creating A File In Application&#39;s Root Location&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-YFYtnFPO9HKwZ0-Ny1y-c6AARgQOy4j5unRbiz_cKTFpqiS3tmkReV7grNUegU-cC_oyR6FCI4HlSPw51H8RRkHz-LxqaD1TFQV1Rm3OCusWpn3BVTSR9XNbTmRQe33H21bk0H4y6_Ha/s1600/creating_new_file.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;492&quot; data-original-width=&quot;1145&quot; height=&quot;273&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-YFYtnFPO9HKwZ0-Ny1y-c6AARgQOy4j5unRbiz_cKTFpqiS3tmkReV7grNUegU-cC_oyR6FCI4HlSPw51H8RRkHz-LxqaD1TFQV1Rm3OCusWpn3BVTSR9XNbTmRQe33H21bk0H4y6_Ha/s640/creating_new_file.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Creating A File In Application&#39;s Root Location&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&amp;nbsp;Verifying If File is Created Successfully Or Not&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRbqy1DQuj6VioSTV0h-PkhXeUGOTdNyGYhqzFwVtiIpPWc2n8ygMoeap1Pdtk3bLQ1D___ccVrB1R5NJxs_D6cGVzoxB9cP-0AoUf2rhWaUVSpnPo0_oDbHUDsXwdrQVwKMKoWSEF0wXI/s1600/check_new_file.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;644&quot; data-original-width=&quot;1156&quot; height=&quot;355&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRbqy1DQuj6VioSTV0h-PkhXeUGOTdNyGYhqzFwVtiIpPWc2n8ygMoeap1Pdtk3bLQ1D___ccVrB1R5NJxs_D6cGVzoxB9cP-0AoUf2rhWaUVSpnPo0_oDbHUDsXwdrQVwKMKoWSEF0wXI/s640/check_new_file.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Verifying If File is Created Successfully Or Not&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: large;&quot;&gt;Protecting Application From Command Injection&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #00120b; font-size: 15px;&quot;&gt;To protect this application against this type of&amp;nbsp;attacks, we will use php&#39;s built-in &lt;/span&gt;&lt;span style=&quot;background-color: white; font-size: 15px;&quot;&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.escapeshellcmd.php&quot; target=&quot;_blank&quot;&gt;escapeshellcmd()&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #00120b; font-size: 15px;&quot;&gt; function. It allows to escape special characters by a backslash.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;Make the following changes in &lt;/span&gt;&lt;span style=&quot;background-color: white; color: #a64d79; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;index.php&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt; file as shown in the below screen shot.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMsE2zbruL1qPMjSJkr8gmlgYXlUO4Mu5RtGdogTKCKu5ppaBpGDZyCXaEchewBOGJYEdWehwst2z4cPYH8yl5ThKj3fe38aK63vf5PsAiRoQOIREm0E-kJ6QdNtAJKqYN5LYJToPMHPIi/s1600/command_injection_prevention_code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protecting Against Command Injection&quot; border=&quot;0&quot; data-original-height=&quot;473&quot; data-original-width=&quot;963&quot; height=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMsE2zbruL1qPMjSJkr8gmlgYXlUO4Mu5RtGdogTKCKu5ppaBpGDZyCXaEchewBOGJYEdWehwst2z4cPYH8yl5ThKj3fe38aK63vf5PsAiRoQOIREm0E-kJ6QdNtAJKqYN5LYJToPMHPIi/s640/command_injection_prevention_code.png&quot; title=&quot;Protecting Against Command Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protecting Against Command Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;After that change, if we try to do &lt;b&gt;command injection&lt;/b&gt;, we won&#39;t see it&#39;s effect anymore.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiomVKPMMNsglQoLM_jgyZ37bYOcvwyl1pFdJivwEbirivNVH76NUdO9s8jyd6p20YNx4fM2MU2EGkiqJ2Ta9jRZOZ2vfdsqKtdq4uXzImk-LIloM3W_JCH88GOLDpsmkQpODvijVquXAG4/s1600/command_injection_prevention.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Proof Of Protecting Against Command Injection&quot; border=&quot;0&quot; data-original-height=&quot;451&quot; data-original-width=&quot;1153&quot; height=&quot;249&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiomVKPMMNsglQoLM_jgyZ37bYOcvwyl1pFdJivwEbirivNVH76NUdO9s8jyd6p20YNx4fM2MU2EGkiqJ2Ta9jRZOZ2vfdsqKtdq4uXzImk-LIloM3W_JCH88GOLDpsmkQpODvijVquXAG4/s640/command_injection_prevention.png&quot; title=&quot;Proof Of Protecting Against Command Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Proof Of Protecting Against Command Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;Final Words&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;I hope you find helpful information after reading this post about command injection in detail, please share it among the others and tell us what you think in comments. Thank you!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: white; color: #00120b; font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: 15px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/command-injection.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5cYEqZhgRSsS5zHzN5XgkS6j5zfUj4-jSG6myEGcJRAyxRWzI5bjwNx8aNGRjffkBfMjnhcI83Dwb-w15RpPgxF-vubY9DYvIJxVvy-Ac0s1HYdLuQS5xF2fv63hrXRlITV2jAhSX9Ysa/s72-c/command-injection-intro-pic.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-3588433205548749567</guid><pubDate>Thu, 20 Jun 2019 22:30:00 +0000</pubDate><atom:updated>2023-03-08T16:10:35.436+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>Top Facts You Need To Know About PHP Code Injection</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMfjBl9m7aHc1NYarulh5hYHfubbpQetd4Hdiq6Zbqx8fudmfrHBBxelmzethxyMq0ko5Rqs9vkfw4IEu8g0MA9IVJtXQtPEFmxmki7D9LIX0wGrTKDS441u0x3zEkuOtKI4zHHN-E7H6v/s1600/php-code-injection-cover-pic.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Cover Image&quot; border=&quot;0&quot; data-original-height=&quot;426&quot; data-original-width=&quot;640&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMfjBl9m7aHc1NYarulh5hYHfubbpQetd4Hdiq6Zbqx8fudmfrHBBxelmzethxyMq0ko5Rqs9vkfw4IEu8g0MA9IVJtXQtPEFmxmki7D9LIX0wGrTKDS441u0x3zEkuOtKI4zHHN-E7H6v/s640/php-code-injection-cover-pic.jpg&quot; title=&quot;PHP Code Injection Cover Image&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-weight: normal;&quot;&gt;What is PHP Code Injection ?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Code injection&lt;/b&gt; is a technique used by attacker to inject server-side code from outside so that it can be evaluated by the corresponding server-side technology.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Code injection allows an attacker to compromise database, security, it is also possible to steal data, bypass access and authentication control. This vulnerability can be easy to find or sometimes it may be harder to find.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;


&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-weight: normal;&quot;&gt;What Can Be Done By Code Injection ?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Code injection attacks are very serious as it leads to compromising application&#39;s data and functionality, also it can gather information about the server that is hosting the application. It is even possible to use the server as a platform to attack other systems.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Code injection&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;capabilities&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;are limited by the&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;functionalities&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;of the language used for the attack. For example, if PHP is used for this purpose, the attack has all the capabilities same as PHP.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Important Note&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Please note that, all the information provided in this post is solely meant for educational purposes only.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;How Does Code Injection Work ?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Generally, web applications are vulnerable to this attack when code is executed without proper input validation.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-weight: normal;&quot;&gt;How To Use Code Injection ?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Let&#39;s see how we can use PHP code injection. For this purpose, we will create a forgot password page, that is vulnerable to code injection.&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Also, we need to add Forgot password link in the login page we created previously, if you haven&#39;t gone through that post, you can read it &lt;a href=&quot;https://devhelperworld.blogspot.com/2019/06/learn-all-about-sql-injection-part-1.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Following is the screen-shot for adding the forgot password link.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUvlg1oDU8DUglwz2twiLhwvn3Sr4zdjPHOLOYn-AC71LlBlZiL0KyDQmjQ0MGitUuxvlYQYrdNIk5akzPOpHOR7ykZgOq5WwceMxTWcNiZgfQKwAC5haEh0HmGZZSaaLIPASv6jRtzP2T/s1600/php-code-injection-login-page-additions.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Forgot Password Added Codes&quot; border=&quot;0&quot; data-original-height=&quot;295&quot; data-original-width=&quot;640&quot; height=&quot;294&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUvlg1oDU8DUglwz2twiLhwvn3Sr4zdjPHOLOYn-AC71LlBlZiL0KyDQmjQ0MGitUuxvlYQYrdNIk5akzPOpHOR7ykZgOq5WwceMxTWcNiZgfQKwAC5haEh0HmGZZSaaLIPASv6jRtzP2T/s640/php-code-injection-login-page-additions.png&quot; title=&quot;PHP Code Injection Forgot Password Added Codes&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Forgot Password Added Codes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Screen shot of forgot password page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnEi1ihWBC0KDHoXphQTJXcz-4M84WmLlduUlCPQ4J606HlrefZQg-_x8pD9GCjspKx2w8FRTjEYj_F1tswDXI-fez5IBMO7-DacIt6YsXzw1WcUeA-S0foNJCt108x3P6mhMErmtUGdig/s1600/php-code-injection-forgot-password-page.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Forgot Password Page&quot; border=&quot;0&quot; data-original-height=&quot;297&quot; data-original-width=&quot;640&quot; height=&quot;296&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnEi1ihWBC0KDHoXphQTJXcz-4M84WmLlduUlCPQ4J606HlrefZQg-_x8pD9GCjspKx2w8FRTjEYj_F1tswDXI-fez5IBMO7-DacIt6YsXzw1WcUeA-S0foNJCt108x3P6mhMErmtUGdig/s640/php-code-injection-forgot-password-page.png&quot; title=&quot;PHP Code Injection Forgot Password Page&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Forgot Password Page&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Getting The Complete PHP Configurations Of The Server&lt;/span&gt;&lt;/h4&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5lCZeEY3J5FlhpNInpGhS3j9-URu4v4aX8edGqHV3QNWgN6OeScwv77RfbynHlQgkpeBoQHI886iHpiHQ6POONa9a8rYPbXwvJzEv_1PIY4GC2byB05I8ifOSuS_oloddSRjkTrzsZgEC/s1600/php-code-injection-getting-php-configurations.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Getting Complete PHP Configurations Of The Server&quot; border=&quot;0&quot; data-original-height=&quot;298&quot; data-original-width=&quot;640&quot; height=&quot;298&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5lCZeEY3J5FlhpNInpGhS3j9-URu4v4aX8edGqHV3QNWgN6OeScwv77RfbynHlQgkpeBoQHI886iHpiHQ6POONa9a8rYPbXwvJzEv_1PIY4GC2byB05I8ifOSuS_oloddSRjkTrzsZgEC/s640/php-code-injection-getting-php-configurations.png&quot; title=&quot;PHP Code Injection Getting Complete PHP Configurations Of The Server&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Getting Complete PHP Configurations Of The Server&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijJeR6La7ChkxQ5K7rFj3hEfnBI2AenettIUankggERuOcT_EVr7FUxtGs9CpmALaeaaEc6muYoah2cq1E7tahaKEg_NcXxBc_24icXnvMuw4L7drAXOb1AQzLluJAPb5V7H_WM53GDOJ3/s1600/php-code-injection-getting-server-root-address.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Getting Document Root Of The Server&quot; border=&quot;0&quot; data-original-height=&quot;194&quot; data-original-width=&quot;640&quot; height=&quot;194&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijJeR6La7ChkxQ5K7rFj3hEfnBI2AenettIUankggERuOcT_EVr7FUxtGs9CpmALaeaaEc6muYoah2cq1E7tahaKEg_NcXxBc_24icXnvMuw4L7drAXOb1AQzLluJAPb5V7H_WM53GDOJ3/s640/php-code-injection-getting-server-root-address.png&quot; title=&quot;PHP Code Injection Getting Document Root Of The Server&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px;&quot;&gt;Getting Document Root Of The Server&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;From the screen shot above, you can see a red rectangle area, that displays the root directory location of the server.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Next, we will look at how an attacker can use this information to create a new file in the application&#39;s&amp;nbsp;root directory.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVWfS1JM6nXFCm8mvdqs07ByjUPHQ9RvqmsT-YYeiosViVKYisO-diZGK5jiKB_ri9zRiV-kzLxi1Ia06vcBkdFcjXOsjvBHayhEvanwOAHSdVsI0hqOx1fCEHQDrBYE0aWTAy7TBV3oPQ/s1600/php-code-injection-file-create.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Creating a New File In Server&#39;s Root Directory&quot; border=&quot;0&quot; data-original-height=&quot;255&quot; data-original-width=&quot;640&quot; height=&quot;254&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVWfS1JM6nXFCm8mvdqs07ByjUPHQ9RvqmsT-YYeiosViVKYisO-diZGK5jiKB_ri9zRiV-kzLxi1Ia06vcBkdFcjXOsjvBHayhEvanwOAHSdVsI0hqOx1fCEHQDrBYE0aWTAy7TBV3oPQ/s640/php-code-injection-file-create.png&quot; title=&quot;PHP Code Injection Creating a New File In Server&#39;s Root Directory&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Creating a New File In The Server&#39;s Root Directory&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Download the entire project by clicking below&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://www.devhelperworld.in/p/download-link-page.html&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Download Button&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggNIKtQcy0dtSmUa_EdtuStTL7oJAvZffCoRvEc0MHqov7dk0SS9V4AQoqvSOXJoIRns6VB-wx5oyQhO-r0gKGhoavaB86FmjZemLkTK6IK2Va5PDNlOnocTLLTbRs2VBLMaOeBpQfNOtQ/s320/download_button.png&quot; title=&quot;Download Button&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Explanation&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the screen shot above, the attacker uses php&#39;s fwrite function to create a text file named &quot;attacker.txt&quot; in root location of application. The error suppression operator &quot;@&quot; is used to ignore error messages that might be generated while fwrite is executed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After successful execution, you will see a text file &lt;span style=&quot;color: #a64d79;&quot;&gt;attacker.txt&lt;/span&gt; is generated, similar to the screen shot shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXQHgz7VIwB9t-YxFw5KD1VtNwueNeRHK8l1c6Kn1CcIoxjYTe0LH4xVyxkRh6wTsN_w9K9hBitLEnROI7fvK3ET2oFPQ4u4_3T-SoZfXwVQX3SAutQ8KC9aKSsTI35LDxApUbv37TQBzA/s1600/php-code-injection-output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;PHP Code Injection Created attacker.txt File In Server&#39;s Root Directory&quot; border=&quot;0&quot; data-original-height=&quot;218&quot; data-original-width=&quot;400&quot; height=&quot;348&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXQHgz7VIwB9t-YxFw5KD1VtNwueNeRHK8l1c6Kn1CcIoxjYTe0LH4xVyxkRh6wTsN_w9K9hBitLEnROI7fvK3ET2oFPQ4u4_3T-SoZfXwVQX3SAutQ8KC9aKSsTI35LDxApUbv37TQBzA/s640/php-code-injection-output.png&quot; title=&quot;PHP Code Injection Created attacker.txt File In Server&#39;s Root Directory&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Created attacker.txt file in server&#39;s root directory&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;How To Prevent PHP Code Injection ?&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Never use the &lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.eval.php&quot; target=&quot;_blank&quot;&gt;eval()&lt;/a&gt;&lt;/span&gt; function to execute any arbitrary php code, as to keep your application safe, you should never trust the input data that is given by the user.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To protect against php code injection, we will use &lt;span style=&quot;color: #674ea7;&quot;&gt;&lt;a href=&quot;https://www.php.net/manual/en/function.htmlspecialchars.php&quot; target=&quot;_blank&quot;&gt;htmlspecialchars()&lt;/a&gt;&lt;/span&gt; function which allows to convert html characters to html entities. For example, &quot;&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;amp;&lt;/span&gt;&quot; will be treated as &quot;&lt;span style=&quot;color: #674ea7;&quot;&gt;&amp;amp;amp&lt;/span&gt;;&quot;. So, the code injection attack will not work anymore.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Make, following changes marked in red rectangle in forgot_password.php file as shown below in the screen shot.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwnT-DcBPdc829rW_9CbinezWNI6z9HsrCnQpPtb7pWEaCf3mJO7YAMvpc7M6yMu_AuzMVvG_TTFvlKuyeJm88z9YdeveUo6nCBtmafXrJUVfFUDMC9vkrPKy3HNqPSvOujNJmrFoVpB8l/s1600/php-code-injection-prevention.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protecting Against PHP Code Injection&quot; border=&quot;0&quot; data-original-height=&quot;360&quot; data-original-width=&quot;640&quot; height=&quot;360&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwnT-DcBPdc829rW_9CbinezWNI6z9HsrCnQpPtb7pWEaCf3mJO7YAMvpc7M6yMu_AuzMVvG_TTFvlKuyeJm88z9YdeveUo6nCBtmafXrJUVfFUDMC9vkrPKy3HNqPSvOujNJmrFoVpB8l/s640/php-code-injection-prevention.png&quot; title=&quot;Protecting Against PHP Code Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protecting Against PHP Code Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span data-mce-style=&quot;font-family: Verdana, sans-serif; font-size: medium; font-weight: 400;&quot; style=&quot;font-size: small; font-weight: 400;&quot;&gt;After making that change, if we try to&amp;nbsp;do&amp;nbsp;&lt;/span&gt;&lt;span data-mce-style=&quot;font-family: Verdana, sans-serif; font-size: medium; font-weight: 400;&quot; style=&quot;font-size: small;&quot;&gt;code injection&lt;/span&gt;&lt;span data-mce-style=&quot;font-family: Verdana, sans-serif; font-size: medium; font-weight: 400;&quot; style=&quot;font-size: small; font-weight: 400;&quot;&gt;, we won&#39;t see any effect of it. So we successfully, prevented &lt;/span&gt;&lt;span data-mce-style=&quot;font-family: Verdana, sans-serif; font-size: medium; font-weight: 400;&quot; style=&quot;font-size: small;&quot;&gt;that attack&lt;/span&gt;&lt;span data-mce-style=&quot;font-family: Verdana, sans-serif; font-size: medium; font-weight: 400;&quot; style=&quot;font-size: small; font-weight: 400;&quot;&gt;. You will see something&amp;nbsp;like&amp;nbsp;the following screen shot if you, do the same.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKqY2uKrQOSSfAlIY0ndsQZRmbYQVNMbtjaOefsSIS64n24cAY46Z0QS7yUTDh3TwvkyZcfBdRBnqlgn0EJj5mownlrQOfNay8zpW0uWcWWYeC7gt7c88Vr81giigkwPua-t97E3vLoRNv/s1600/php-code-injection-prevention-output.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protecting Against PHP Code Injection Output&quot; border=&quot;0&quot; data-original-height=&quot;296&quot; data-original-width=&quot;640&quot; height=&quot;296&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKqY2uKrQOSSfAlIY0ndsQZRmbYQVNMbtjaOefsSIS64n24cAY46Z0QS7yUTDh3TwvkyZcfBdRBnqlgn0EJj5mownlrQOfNay8zpW0uWcWWYeC7gt7c88Vr81giigkwPua-t97E3vLoRNv/s640/php-code-injection-prevention-output.png&quot; title=&quot;Protecting Against PHP Code Injection Output&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protecting Against PHP Code Injection Output&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Conclusion&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you like this post, please share among the others, as you know sharing is caring.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/php-code-injection.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMfjBl9m7aHc1NYarulh5hYHfubbpQetd4Hdiq6Zbqx8fudmfrHBBxelmzethxyMq0ko5Rqs9vkfw4IEu8g0MA9IVJtXQtPEFmxmki7D9LIX0wGrTKDS441u0x3zEkuOtKI4zHHN-E7H6v/s72-c/php-code-injection-cover-pic.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-6778125212928566498</guid><pubDate>Sat, 15 Jun 2019 09:06:00 +0000</pubDate><atom:updated>2023-03-08T16:10:38.581+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>Vs Code Setup For PHP Development</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVLmAtA-xyQkUbYOVX873qdqL9tFtkXTBs4TB8qk8mQX9v5TbUZFs7ChCGKy_mz1y3DAmphT5Tiu6jUKQ0nSxyNMojXw6Qltuh-W9hFbYC8bK2lpO0VgzPwnptxmuhup-_rJt418WOqFFn/s1600/visual-studio-code-setup-for-php.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;visual-studio-code-setup-for-php&quot; border=&quot;0&quot; data-original-height=&quot;533&quot; data-original-width=&quot;800&quot; height=&quot;426&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVLmAtA-xyQkUbYOVX873qdqL9tFtkXTBs4TB8qk8mQX9v5TbUZFs7ChCGKy_mz1y3DAmphT5Tiu6jUKQ0nSxyNMojXw6Qltuh-W9hFbYC8bK2lpO0VgzPwnptxmuhup-_rJt418WOqFFn/s640/visual-studio-code-setup-for-php.jpg&quot; title=&quot;visual-studio-code-setup-for-php&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Internet is a great resource for information, you will be able to find tons of articles online that will guide you to setup &lt;b&gt;visual studio code&lt;/b&gt;. If you find any of them useful enough, you can skip reading this post. Otherwise, you can keep going on.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;&lt;a href=&quot;https://devhelperworld.blogspot.com/2019/06/vs-code-setup.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;Visual Studio Code&lt;/b&gt;&lt;/a&gt; provides easier way to install plugins, so you don&#39;t have to waste your time configuring it for this purpose. You need to open extensions option after opening &lt;a href=&quot;https://devhelperworld.blogspot.com/2019/06/vs-code-setup.html&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;visual studio code&lt;/b&gt;&lt;/a&gt; which can be seen in the screen shot below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVw-Y3c40KrLi9l3fU5pY_WgGd1IGBdhL_p9-aGv4gGhpdQAOhND0NJbbf_W64vdsNhgyqj6EKiro1q6-j_L7RqORWZSv_SgmleOObRlw2lGjS9hSZiqDwk8ipFk8d8selejcAhLNU_gza/s1600/vs_code_sidebar.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;vs-code-extensions-tab&quot; border=&quot;0&quot; data-original-height=&quot;309&quot; data-original-width=&quot;417&quot; height=&quot;296&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVw-Y3c40KrLi9l3fU5pY_WgGd1IGBdhL_p9-aGv4gGhpdQAOhND0NJbbf_W64vdsNhgyqj6EKiro1q6-j_L7RqORWZSv_SgmleOObRlw2lGjS9hSZiqDwk8ipFk8d8selejcAhLNU_gza/s400/vs_code_sidebar.png&quot; title=&quot;vs-code-extensions-tab&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the search bar, type &quot;&lt;span style=&quot;color: #a64d79;&quot;&gt;PHP IntelliSense&lt;/span&gt;&quot;. Click on install button. After it finishes installation. You need to configure this plugin, so that it will be able to communicate directly with the PHP executable file. If this communication is done in a right way, then this plugin will function correctly.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Configuring PHP IntelliSense&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In &lt;b&gt;visual studio code&lt;/b&gt;, in the menu bar, go to File-&amp;gt;Preferences-&amp;gt;Settings. In the Settings search bar, type &quot;PHP&quot;, you can see similar result as shown below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTGSGz9VJ-vGRaP23jhuInT3mqrvskk9z2PLrQFfBQkCnF3dqZnZQ4H8nhjNSMzWqgd0-QoAusQcMNSGkTY7819WNJz7b3GqvdW9kmd6Z3egJ7n7RSm8lUFw39nuz1Jtfhcms0bkAqTVcw/s1600/vs_code_settings.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;vs-code-phpintellisense-plugin-setup&quot; border=&quot;0&quot; data-original-height=&quot;522&quot; data-original-width=&quot;1210&quot; height=&quot;172&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTGSGz9VJ-vGRaP23jhuInT3mqrvskk9z2PLrQFfBQkCnF3dqZnZQ4H8nhjNSMzWqgd0-QoAusQcMNSGkTY7819WNJz7b3GqvdW9kmd6Z3egJ7n7RSm8lUFw39nuz1Jtfhcms0bkAqTVcw/s400/vs_code_settings.png&quot; title=&quot;vs-code-phpintellisense-plugin-setup&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Select &lt;span style=&quot;color: #a64d79;&quot;&gt;PHP IntelliSense&lt;/span&gt; option, then click on &lt;b&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;Edit in Settings.json&lt;/span&gt;&lt;/b&gt;. You need to add following settings (that are marked inside red rectangle) in that file.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtAGTOWD5qbt1HvkMleXtxL-0ch-v6mNCTLXwlHNHYddrruFo8Pv-vIGMqhGpZss-T_uMYSgKyXMS_K2TFhNBri77LMeK9DmmXbNP1wxEkNif6P9riH3Es84VsBQef3-iYRhBPtAfS9g0A/s1600/vs_code_php.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;vs-code-phpintellisense-plugin-settings&quot; border=&quot;0&quot; data-original-height=&quot;328&quot; data-original-width=&quot;901&quot; height=&quot;145&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtAGTOWD5qbt1HvkMleXtxL-0ch-v6mNCTLXwlHNHYddrruFo8Pv-vIGMqhGpZss-T_uMYSgKyXMS_K2TFhNBri77LMeK9DmmXbNP1wxEkNif6P9riH3Es84VsBQef3-iYRhBPtAfS9g0A/s400/vs_code_php.png&quot; title=&quot;vs-code-phpintellisense-plugin-settings&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the screen shot above, the third option (i.e, &lt;b&gt;php.executablePath&lt;/b&gt; ) refers to the location where you have installed php. This may vary for different operating systems. The example shown here is meant for Windows operating system.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;That&#39;s it, you have successfully configured &lt;b&gt;PHP IntelliSense&lt;/b&gt; to speed up PHP development.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Final Words&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you find this post helpful, don&#39;t forget to share. Thank you!&lt;/span&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/vs-code-setup.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVLmAtA-xyQkUbYOVX873qdqL9tFtkXTBs4TB8qk8mQX9v5TbUZFs7ChCGKy_mz1y3DAmphT5Tiu6jUKQ0nSxyNMojXw6Qltuh-W9hFbYC8bK2lpO0VgzPwnptxmuhup-_rJt418WOqFFn/s72-c/visual-studio-code-setup-for-php.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-9016750373762225141</guid><pubDate>Sat, 15 Jun 2019 05:34:00 +0000</pubDate><atom:updated>2023-03-08T16:10:41.778+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>SQL Injection Step By Step Part 2</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This post is the final part of sql injection series. If you missed the first part, you can read it &lt;a href=&quot;https://www.devhelperworld.in/2019/06/sql-injection-part-1.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
What We Will Be Creating&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We will create a post listing page, where user can search any post by entering post title or description.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Posts Home Page&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;356&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOfogarGkcvYZEzY2txb3Toh1RSmLj2hGUYI4Vz2Q1nbJ51mWnUElZCPTMbDJze4XFg83Mw4qVi-FFaO_m0VlVXyK27uuHP2D1GquKDIXVLCaz0ZmlB8A5Xubj9kOr6uFav536WARArmoK/s640/posts_home_page.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;Posts Home Page&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;
Creating The Posts Table&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You may wonder that how the posts are displayed in the post page. If you see the screenshot above, user is unable to create posts, as no form is provided for the them to do that.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Well, I did it intentionally, so that you can focus on learning the inner-workings of sql injection in depth.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To make the posts visible in that way, we need to create the posts table using php myadmin utility that we can use by entering this url &quot;&lt;a href=&quot;http://localhost/phpmyadmin/&quot;&gt;http://localhost/phpmyadmin/&lt;/a&gt;&quot; in the browser, after we start apache server and mysql&amp;nbsp;database service from the XAMPP control panel.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The table structure for the posts table is as follows.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Posts Table Structure&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;356&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHcvYXtjVgKPcmkDy0DQfa1JM2UgMeVSgH1iEG8BOvYkoG818pTf5Nvx1Wo2LMuwuHTXoCWrGmDI9O_zARpEEQ_gdgPY7metsQoQbrF7jXPHJHBc2d3bcyMgK-hcMya-sB6PxT3uHpyvPL/s640/posts_tbl_structure.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;Posts Table Structure&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Posts Table Structure&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHcvYXtjVgKPcmkDy0DQfa1JM2UgMeVSgH1iEG8BOvYkoG818pTf5Nvx1Wo2LMuwuHTXoCWrGmDI9O_zARpEEQ_gdgPY7metsQoQbrF7jXPHJHBc2d3bcyMgK-hcMya-sB6PxT3uHpyvPL/s1600/posts_tbl_structure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The data for the posts table is as follows.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjYKJubKiCSiU7GsHj-LI8Ho726QiUzZGiB-qXG1PYeLsffFxStk2AZaQ-Qcxan5xqVxPRs6jQOA5w1ECEQNkYwYl6FMlfxZwEDTePK6f6lpSW63T88JhQlDQPUd7_4hI43Yr1xTXRN8KL/s1600/posts_tbl_data.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Posts Table Data&quot; border=&quot;0&quot; data-original-height=&quot;190&quot; data-original-width=&quot;1019&quot; height=&quot;116&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjYKJubKiCSiU7GsHj-LI8Ho726QiUzZGiB-qXG1PYeLsffFxStk2AZaQ-Qcxan5xqVxPRs6jQOA5w1ECEQNkYwYl6FMlfxZwEDTePK6f6lpSW63T88JhQlDQPUd7_4hI43Yr1xTXRN8KL/s640/posts_tbl_data.png&quot; title=&quot;Posts Table Data&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Posts Table Data&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Download the entire project by clicking below&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://www.devhelperworld.in/p/download-link-page.html&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggNIKtQcy0dtSmUa_EdtuStTL7oJAvZffCoRvEc0MHqov7dk0SS9V4AQoqvSOXJoIRns6VB-wx5oyQhO-r0gKGhoavaB86FmjZemLkTK6IK2Va5PDNlOnocTLLTbRs2VBLMaOeBpQfNOtQ/s320/download_button.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;
Explanation of posts.php&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this page, at first we checked if the user is already logged in or not. If the user is logged in then he or she can view the posts page, otherwise he or she is redirected to the login page.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We took the search keyword from the textbox, when user submits the form, we collect the textbox content through GET request.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Then, we checked if any match is found by comparing post&#39;s title or description with the search keyword. If any match is found we display the results in a table. If no posts exist matching the exact keyword, we displayed a message &quot;No posts found!&quot;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If for some reason, the database is unable to process the search keyword, we displayed a sql error to the user.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Extracting The Complete Database Details&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;We completed the posts search functionality for this application. Let&#39;s see how to exploit this application, so that we can get the complete database details from it. For this purpose, we will be using &lt;a href=&quot;https://en.wikipedia.org/wiki/Set_operations_(SQL)&quot; target=&quot;_blank&quot;&gt;UNION operator&lt;/a&gt; of MySQL database.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Basics Of UNION Operator&lt;/span&gt;&lt;/h4&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;UNION operator is used so that we can chain together multiple results of two or more sql statements.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Each SELECT statement withing UNION, must have equal number of columns.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;So, we now know, what are the basic requirements to run UNION statements successfully. Let&#39;s see how we can do that.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;To do that, we need to use ORDER BY clause of MySQL. We will enter a specific ORDER BY statement in search textbox and see if any sql error is displayed. If this happens, then we will simply decrease the numeric value that we used in that ORDER BY clause.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If we saw, &quot;No posts found!&quot; message, then it&#39;s ok, we can check again by increasing the numeric value that we used in the ORDER BY clause. After completing this step, we can get total number of columns in the posts table.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The screen shot of first attempt is shown below.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;First Attempt To Get Number Of Columns&quot; border=&quot;0&quot; data-original-height=&quot;439&quot; data-original-width=&quot;1341&quot; height=&quot;208&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-tWxv85XGj-tP2sf2oxT-odkNDU3SCfPdmWgJtqeFv_NlCZFwtRYS6CPbMFP0s92V_n_aMH-FgWtSOw451U4xM5m8PT1jIm9Id4eZDMQNrUGX_hlduqtvm1KWani1wOR05ytc4OcU-QM_/s640/num_of_columns1.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;First Attempt To Get Number Of Columns&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;First Attempt To Get Number Of Columns&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-tWxv85XGj-tP2sf2oxT-odkNDU3SCfPdmWgJtqeFv_NlCZFwtRYS6CPbMFP0s92V_n_aMH-FgWtSOw451U4xM5m8PT1jIm9Id4eZDMQNrUGX_hlduqtvm1KWani1wOR05ytc4OcU-QM_/s1600/num_of_columns1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The screen shot of final attempt is shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Final Attempt To Get Number Of Columns&quot; border=&quot;0&quot; data-original-height=&quot;424&quot; data-original-width=&quot;1342&quot; height=&quot;201&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguQSrkpRshKtWWUnm4w791JgWAyT21KGrEgCTRg-TVkXTR8pGA4VeUf-MVrFwSPqwFr7U9eM4bVdQQQWMv_eJhf_fOaGd2QTVrOK9w10HJGxCcTWr2dn3eRegKxuXlJnPYYFpM5qfba7qK/s640/num_of_columns_final.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;Final Attempt To Get Number Of Columns&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;font-size: 12.8px;&quot;&gt;Final Attempt To Get Number Of Columns&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-size: medium;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-tWxv85XGj-tP2sf2oxT-odkNDU3SCfPdmWgJtqeFv_NlCZFwtRYS6CPbMFP0s92V_n_aMH-FgWtSOw451U4xM5m8PT1jIm9Id4eZDMQNrUGX_hlduqtvm1KWani1wOR05ytc4OcU-QM_/s1600/num_of_columns1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;From the above screen shot, we saw the error message. So, we know that, the posts table contains exactly 4 columns.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&amp;nbsp;Let&#39;s use this information to get a lot of information about the database that is being used in this application.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Getting MySQL Database Name&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Getting Mysql Database Name&quot; border=&quot;0&quot; data-original-height=&quot;482&quot; data-original-width=&quot;1343&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyQL7YBniUbjPmvUcMOCioOeq3WZhi5G8ZnaC8sPtPHkNo3DiS5LDFhZNYns9KWpEG_WkOcDEntV-uybisjDSfUZ_qcGW2nM4DP33ZHtkwhyphenhyphennemRisWlEuusqEmNixEXm14J626swROQvg/s640/get_db_details.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;Getting Mysql Database Name&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Getting Mysql Database Name&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyQL7YBniUbjPmvUcMOCioOeq3WZhi5G8ZnaC8sPtPHkNo3DiS5LDFhZNYns9KWpEG_WkOcDEntV-uybisjDSfUZ_qcGW2nM4DP33ZHtkwhyphenhyphennemRisWlEuusqEmNixEXm14J626swROQvg/s1600/get_db_details.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Getting MySQL Database Tables&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Getting Mysql Database Tables&quot; border=&quot;0&quot; data-original-height=&quot;520&quot; data-original-width=&quot;1341&quot; height=&quot;248&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyv8WXuoEzJr-DljJgbHc8579_Dzy8nwOkY4OUp_kpTmUw0VUatgYZQOcq3ZfynAMDQI4ygwg9tfcygKCEtjM513rNas_Zpt5K2o_QkKakoFwSLtPoCf5s24ZSC0OzV4pnE63ijyvwHVbc/s640/list_of_tables.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;Getting Mysql Database Tables&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Getting Mysql Database Tables&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyv8WXuoEzJr-DljJgbHc8579_Dzy8nwOkY4OUp_kpTmUw0VUatgYZQOcq3ZfynAMDQI4ygwg9tfcygKCEtjM513rNas_Zpt5K2o_QkKakoFwSLtPoCf5s24ZSC0OzV4pnE63ijyvwHVbc/s1600/list_of_tables.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Getting Columns Of users Table&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;Getting Columns Of users Table&quot; border=&quot;0&quot; data-original-height=&quot;474&quot; data-original-width=&quot;1346&quot; height=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1wyijelq8RWzyvWHX98-R4JkKceugPt3KXjBrJMl5MLwTnzByw2Geu-uth6JvHatvAIFikxZniEaWPUAl4kEoj5N_Fh3E6Pp3YoocevIheB2Fl1IGI7RHrKS7VC2yOfq9EuQSyGAOrKLN/s640/users_table_columns.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; title=&quot;Getting Columns Of users Table&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;div class=&quot;graf graf--p&quot; name=&quot;f53d&quot;&gt;
Getting Columns Of users Table&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1wyijelq8RWzyvWHX98-R4JkKceugPt3KXjBrJMl5MLwTnzByw2Geu-uth6JvHatvAIFikxZniEaWPUAl4kEoj5N_Fh3E6Pp3YoocevIheB2Fl1IGI7RHrKS7VC2yOfq9EuQSyGAOrKLN/s1600/users_table_columns.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Getting id, username and password Columns Of users Table&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;484&quot; data-original-width=&quot;1340&quot; height=&quot;228&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjirXVJo4MG-Jh4yZOeamAsLq2pp2MhdXLtWlJSANDVamKPQ3Y_uw3E0pTe50IYP8FJOB0RS38QFWYuJHG1J81yfqrf-PgDhWY7l0lR6dOVhi1RrNXQFNrKkt5MbVDJ-IuVJuHkbO2Rchsi/s640/users_table_records.png&quot; style=&quot;margin-left: auto; margin-right: auto;&quot; width=&quot;640&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Getting id, username and password columns of users Table&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjirXVJo4MG-Jh4yZOeamAsLq2pp2MhdXLtWlJSANDVamKPQ3Y_uw3E0pTe50IYP8FJOB0RS38QFWYuJHG1J81yfqrf-PgDhWY7l0lR6dOVhi1RrNXQFNrKkt5MbVDJ-IuVJuHkbO2Rchsi/s1600/users_table_records.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Preventing SQL Injection&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you want to&amp;nbsp;prevent SQL Injection, then this section will help you to understand&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;preventing SQL Injection&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;completely. If you don&#39;t know what is sql injection, you can read it&amp;nbsp;&lt;a href=&quot;https://www.devhelperworld.in/2019/06/sql-injection.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In order to&amp;nbsp;prevent SQL injection, you will able to get a set of practical examples, so that you won&#39;t find it difficult to understand the concept.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;What We Will Do&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Previously, we saw how an attacker used sql injection to bypass login, exploit the database and was able to get detail information about the database. Now, we will stop the attacker from doing that.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Protecting The Login Page&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In the following screen shot, the highlighted text marked in white color, will protect all types of sql injection attacks.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzP7kOhuac37Paamtbt2fr8t2vYUyhVDbDYFri3k9fRfOdKf9-GeIzZBH-9icZ0NOsPbj2FbmlgWb9r0nsidieNdNXcKIL_Hy_oLb1AwZ5bji7vgjJACO8cG1RPlux2AVXdsIO2OLFyKIa/s1600/protected_1_code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protecting Login Page From Sql Injection&quot; border=&quot;0&quot; data-original-height=&quot;460&quot; data-original-width=&quot;1098&quot; height=&quot;268&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzP7kOhuac37Paamtbt2fr8t2vYUyhVDbDYFri3k9fRfOdKf9-GeIzZBH-9icZ0NOsPbj2FbmlgWb9r0nsidieNdNXcKIL_Hy_oLb1AwZ5bji7vgjJACO8cG1RPlux2AVXdsIO2OLFyKIa/s640/protected_1_code.png&quot; title=&quot;Protecting Login Page From Sql Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protecting Login Page From Sql Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After making those changes, refresh the login page, and try doing that login bypass attack again, you will see something like the screen shot shown below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaRRTw0j72aMoed8FXAYiYAjHha_ztROgpo-vK0_4qOPyNErFNdsEkUVrUrOlTu3Zvd9k6MMDvKJiJzOzkyD8FeOk89rLir5W3ebasDTQBhsSvaG-3jncYXBC1KcVjyWK4xK8P9RDiZoKH/s1600/protected_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protected Login Page From Sql Injection&quot; border=&quot;0&quot; data-original-height=&quot;620&quot; data-original-width=&quot;1059&quot; height=&quot;374&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaRRTw0j72aMoed8FXAYiYAjHha_ztROgpo-vK0_4qOPyNErFNdsEkUVrUrOlTu3Zvd9k6MMDvKJiJzOzkyD8FeOk89rLir5W3ebasDTQBhsSvaG-3jncYXBC1KcVjyWK4xK8P9RDiZoKH/s640/protected_1.png&quot; title=&quot;Protected Login Page From Sql Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protected Login Page From Sql Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Protecting The Posts Page&lt;/span&gt;&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Simply, add marked code as shown in the screen shot below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0H0coWZr0EbfIlPOCdEaketqq_g9GqWMmFg9F4bgkfxSRLfJ7L-XDuBZxtL4KY_SdcMFM0EE1vDY7XiZsEvtGY2n8Y4wPOrLHKwT8FDVyCi1oifsiHNjrPd7tF6GkUNrGu0HvpPhWjI7E/s1600/protected_2_code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protecting Posts Page From Sql Injection&quot; border=&quot;0&quot; data-original-height=&quot;478&quot; data-original-width=&quot;1153&quot; height=&quot;264&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0H0coWZr0EbfIlPOCdEaketqq_g9GqWMmFg9F4bgkfxSRLfJ7L-XDuBZxtL4KY_SdcMFM0EE1vDY7XiZsEvtGY2n8Y4wPOrLHKwT8FDVyCi1oifsiHNjrPd7tF6GkUNrGu0HvpPhWjI7E/s640/protected_2_code.png&quot; title=&quot;Protecting Posts Page From Sql Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protecting Posts Page From Sql Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After completing this step, try executing sql injection attacks that used union statement. You will see similar outcome as shown in screen shot below.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgi7nhhuY_sgbBJu8uDyAHOHqQ5hYmygpimHnRJORC4DouRcpbip_WDdf99QdvozZ-9Bd0X0sCaluJBT-W9ewuJTzqOTq3M5E0LRKPAVCOpGBVunPdvMrgsznDHZp7uZCWHVLmxnpMNaZyc/s1600/protected_2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Protected Posts Page From Sql Injection&quot; border=&quot;0&quot; data-original-height=&quot;429&quot; data-original-width=&quot;1171&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgi7nhhuY_sgbBJu8uDyAHOHqQ5hYmygpimHnRJORC4DouRcpbip_WDdf99QdvozZ-9Bd0X0sCaluJBT-W9ewuJTzqOTq3M5E0LRKPAVCOpGBVunPdvMrgsznDHZp7uZCWHVLmxnpMNaZyc/s640/protected_2.png&quot; title=&quot;Protected Posts Page From Sql Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Protected Posts Page From Sql Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Final Words&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif; font-size: small;&quot;&gt;If
you find this post about learning &lt;b&gt;sql injection step by step part 2&lt;/b&gt;
as helpful, please share it with others. Thank you!&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/sql-injection-part-2.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOfogarGkcvYZEzY2txb3Toh1RSmLj2hGUYI4Vz2Q1nbJ51mWnUElZCPTMbDJze4XFg83Mw4qVi-FFaO_m0VlVXyK27uuHP2D1GquKDIXVLCaz0ZmlB8A5Xubj9kOr6uFav536WARArmoK/s72-c/posts_home_page.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-6136114203279243565</guid><pubDate>Mon, 10 Jun 2019 18:01:00 +0000</pubDate><atom:updated>2023-03-08T16:10:44.444+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>Speed Up Web Development With Emmet For Sublime Text 3</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1tt-WJAmlumNB2dtewVuZ6xj9ZE2tKpgFZliL9VlvBasPeHbKvNuoW1dqEXSjGzTOvZL2FeH5VZ-Z3ZqIApVe8D23pL3h6JlpLrnaDzI4OpZsJVJa0U767Mah_o0OAkKhBfNSTmK68Ie7/s1600/setup-sublime-text-php.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;setup-sublime-text-php&quot; border=&quot;0&quot; data-original-height=&quot;853&quot; data-original-width=&quot;1280&quot; height=&quot;425&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1tt-WJAmlumNB2dtewVuZ6xj9ZE2tKpgFZliL9VlvBasPeHbKvNuoW1dqEXSjGzTOvZL2FeH5VZ-Z3ZqIApVe8D23pL3h6JlpLrnaDzI4OpZsJVJa0U767Mah_o0OAkKhBfNSTmK68Ie7/s640/setup-sublime-text-php.jpg&quot; title=&quot;setup-sublime-text-php&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You can find tons of information on the internet to set up &lt;a href=&quot;https://devhelperworld.blogspot.com/2019/06/sublime-text-setup.html&quot; target=&quot;_blank&quot;&gt;sublime text&lt;/a&gt; for development. If you like to follow any of them you can skip reading this post. If you are ready, keep going on.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Install Package Control&amp;nbsp;&lt;/h3&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Sublime text is able to download and use 3rd party plugins by using something known as Package Control. I found following video very useful for this purpose.&lt;/span&gt;&lt;br /&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/lx9nIHABnmY&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After installing package control, now you can begin searching for useful plugins and then install them one by one as per your choice.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Open search bar by pressing Ctrl + Shift + P keys combination on keyboard for windows and Cmd + Shift + P keys combination for Mac OS.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;You will see something similar to this as shown below.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipszSFkoZu4eJ-8nm3AFjkdyu2yswlGTcqBgovJyq66xRuQtXu1p5t7omWsm7JvtHOEDGNSx13w_CU_FTpIy3TDD91OaGBtMpdsp1f5kUlZDbpI7pb7qU7wjABv9hWkVmSNLJlGCYOkKUC/s1600/search_bar.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;sublime-package-control &quot; border=&quot;0&quot; data-original-height=&quot;477&quot; data-original-width=&quot;980&quot; height=&quot;193&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipszSFkoZu4eJ-8nm3AFjkdyu2yswlGTcqBgovJyq66xRuQtXu1p5t7omWsm7JvtHOEDGNSx13w_CU_FTpIy3TDD91OaGBtMpdsp1f5kUlZDbpI7pb7qU7wjABv9hWkVmSNLJlGCYOkKUC/s400/search_bar.png&quot; title=&quot;sublime-package-control &quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Type &quot;Install Package&quot; (without quotes) and press enter key on keyboard, you will see lot of plugins to install.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmh8c9nkxXinR2YvhW0lNd5emiV9gcsTrlWJBuV7q1WqSuTxHiy-rxJ1Gn5Oi8fzCI1l5p1DWO5Gh6V-m24DZrA73-BuoXVnxCzgKO4iKd7DJmVOEIuNXPrXu0PDxJulmSiJv_8F6kwKr_/s1600/plugins_list.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;sublime-package-control-plugin&quot; border=&quot;0&quot; data-original-height=&quot;485&quot; data-original-width=&quot;1032&quot; height=&quot;150&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmh8c9nkxXinR2YvhW0lNd5emiV9gcsTrlWJBuV7q1WqSuTxHiy-rxJ1Gn5Oi8fzCI1l5p1DWO5Gh6V-m24DZrA73-BuoXVnxCzgKO4iKd7DJmVOEIuNXPrXu0PDxJulmSiJv_8F6kwKr_/s320/plugins_list.png&quot; title=&quot;sublime-package-control-plugin&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Now, install the plugins that I mentioned below.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;Emmet&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;SublimeLinter&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;SublimeLinter-php&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;PHP Companion&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;PHP Completions Kit&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;PHPIntel&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Above mentioned plugins are must to speed up PHP development. The setup process for SublimeLinter is a bit tricky, so I share &lt;a href=&quot;https://www.youtube.com/watch?v=8DO_VylgxNc&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt; link, so that you can follow along easily.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;PHP linter tool will help you by displaying PHP errors, while you are writing your code. You can install other plugins easily. It won&#39;t be that hard.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;I would specially like to mention about the Emmet plugin. It will help you to write HTML and CSS code more easily and efficiently. It will also save your time a lot. Please see &lt;a href=&quot;https://docs.emmet.io/cheat-sheet/&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt; cheat sheet for valid commands list for emmet. Personally I use emmet often.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Final Words&lt;/h4&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you find this post helpful, don&#39;t forget to share. Thank you!&lt;/span&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/sublime-text-setup.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1tt-WJAmlumNB2dtewVuZ6xj9ZE2tKpgFZliL9VlvBasPeHbKvNuoW1dqEXSjGzTOvZL2FeH5VZ-Z3ZqIApVe8D23pL3h6JlpLrnaDzI4OpZsJVJa0U767Mah_o0OAkKhBfNSTmK68Ie7/s72-c/setup-sublime-text-php.jpg" height="72" width="72"/><thr:total>6</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-14127877075328922</guid><pubDate>Thu, 06 Jun 2019 17:02:00 +0000</pubDate><atom:updated>2023-03-08T16:10:47.109+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>SQL Injection Step By Step Part 1</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
If you want to learn &lt;b&gt;SQL Injection step by step&lt;/b&gt;, then after reading this article will help you to understand SQL Injection step by step with example completely.&lt;br /&gt;
&lt;br /&gt;
In order to understand SQL injection step by step, this article provides a set of practical examples, so that you won&#39;t find it difficult to understand &lt;b&gt;SQL injection step by step&lt;/b&gt; with example.&lt;br /&gt;
&lt;br /&gt;
SQL injection is a common vulnerability of a web application. If this vulnerability is not taken care of by the web developer, then it can lead to complete disclosure of all data of the system and the list grows!&lt;br /&gt;
&lt;br /&gt;
In my earlier post, I wrote about what is &lt;b&gt;SQL injection, &lt;/b&gt;how it works and what can be done with &lt;b&gt;SQL injection&lt;/b&gt;. If you haven&#39;t gone through that post, please read it &lt;a href=&quot;https://www.devhelperworld.in/2019/06/sql-injection.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;, and then come back.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Important Note&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Please note that, all the information provided in this post is solely meant for educational purposes only.&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;Let&#39;s
see how we can use&amp;nbsp;&lt;b&gt;sql
injection&lt;/b&gt;&amp;nbsp;to an
application, but before that, we need to create that application from
scratch.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;h4 align=&quot;LEFT&quot; class=&quot;western&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;What
We Will Be Creating&lt;/span&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;We
will be building a registration and login page for a web application
with PHP.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5M3x-L8lapa4e-9DUyDSuphRIUY9t5FTRMs-OGV0NTWq82EYQSjiFC6qpESPg3ubmzegOs1vU1jX60dEb2XGU3n-8U18_qXrfh04NqUYMOn621ohsK-KS-6JWFH8vdsDTE_N-bsXeSu-z/s1600/app_login.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Login Page&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5M3x-L8lapa4e-9DUyDSuphRIUY9t5FTRMs-OGV0NTWq82EYQSjiFC6qpESPg3ubmzegOs1vU1jX60dEb2XGU3n-8U18_qXrfh04NqUYMOn621ohsK-KS-6JWFH8vdsDTE_N-bsXeSu-z/s640/app_login.png&quot; title=&quot;Login Page&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;&lt;b&gt;&lt;br /&gt;Required
Technical Skills&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;Basic
knowledge on following&amp;nbsp; technologies are necessary.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;HTML&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;CSS&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;Jquery
 / Javascript&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;Bootstrap&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;PHP&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;&lt;div align=&quot;LEFT&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;SQL&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;b&gt;Required
Tools/Softwares&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;1)
Local Web Server&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;It
is required, as PHP is a server side scripting technology, so in
order to run PHP scripts, we need a local web server, as it is very
easy to use and it is completely free of cost. I will be using XAMPP
as local web server.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;2)
Text Editor / IDE (Integrated Development Environment)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;A
text editor / IDE of your choice for writing your code, if you&#39;re
using Sublime Text, then read&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;https://devhelperworld.blogspot.com/2019/06/sublime-text-setup.html&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp;to
configure sublime text for development.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;If
you&#39;re using Visual Studio Code, then read&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;https://devhelperworld.blogspot.com/2019/06/vs-code-setup.html&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&amp;nbsp;to
configure it for development.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;I
personally preferred Sublime text for a long time. But, right now, I
started using Visual Studio Code, and I like pretty much everything
about it.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;&lt;b&gt;Overall
Project Structure&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj592NmlnOJ3AHcPGO4oHIWYDxeJAtHsp6SCyZE53SXXHBIXxOh59SSX70ZmJ9HdigRw1MpVgNVmOSrALhmYxqJD5iYYx_2fhg9Nlvttwevr__XBkW0qTDas96AEJ0gwAXuaIurom6bX6qs/s1600/project_structure.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;Overall Project Structure&quot; border=&quot;0&quot; data-original-height=&quot;190&quot; data-original-width=&quot;123&quot; height=&quot;400&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj592NmlnOJ3AHcPGO4oHIWYDxeJAtHsp6SCyZE53SXXHBIXxOh59SSX70ZmJ9HdigRw1MpVgNVmOSrALhmYxqJD5iYYx_2fhg9Nlvttwevr__XBkW0qTDas96AEJ0gwAXuaIurom6bX6qs/s400/project_structure.png&quot; title=&quot;Overall Project Structure&quot; width=&quot;258&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0cm; margin-top: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Discussion
on project structure&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: normal; margin-bottom: 0cm; margin-top: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: orange;&quot;&gt;&lt;b&gt;.phpintel&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;:
This file is generated automatically if we use PHPIntel plugin for
sublime text.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;All
other files having .php extensions are self explanatory. E.g,
register.php contains HTML markup along-with PHP scripts required for
registration etc.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: orange; font-family: inherit;&quot;&gt;&lt;b&gt;css&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;:
 This folder contains all the necessary css (cascading style sheet)
 files required for this project.&lt;/span&gt;&lt;br /&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: orange; font-family: inherit;&quot;&gt;&lt;b&gt;js&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;:
 It contains all javascript files used in this project.&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;All
other files having .php extensions are self explanatory. E.g,
register.php contains HTML markup along-with PHP scripts required for
registration etc.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;Creating
The Database And Users Table&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Open
the browser, type in &quot;&lt;span style=&quot;color: #a64d79;&quot;&gt;http://localhost/phpmyadmin&lt;/span&gt;&quot;
in url bar, then create a database as &quot;hacking_db&quot; and
create a table as &quot;users&quot;. If you find any difficulties
doing so, you can watch the tutorial as shown below &amp;nbsp;(watch till
3:50 min).&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;iframe allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot; frameborder=&quot;0&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/5QHBj4brHNM&quot; width=&quot;560&quot;&gt;&lt;/iframe&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;The
screenshot for the structure of users table is as follows.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh5bKFDtOAVMdxWaWl-dOtrhVYaIAtfvfVptrFsTm29l_x3Br52awWap6cn9gw4pvdShlQDzOO_4JaXZMKtzF5FG21P0uoIqS8JCFDSdFK4AO1cbsdiIfk6Lkx0bjwnrM_une1j2G9itct/s1600/table_setup.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Users Table Structure&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjh5bKFDtOAVMdxWaWl-dOtrhVYaIAtfvfVptrFsTm29l_x3Br52awWap6cn9gw4pvdShlQDzOO_4JaXZMKtzF5FG21P0uoIqS8JCFDSdFK4AO1cbsdiIfk6Lkx0bjwnrM_une1j2G9itct/s640/table_setup.png&quot; title=&quot;Users Table Structure&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Users Table Structure&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Download the entire project by clicking below.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://www.devhelperworld.in/p/download-link-page.html&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;Download Button&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;960&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKIpJ-5M33yLJ4UAjgPP0KvGWV41M6cMP77Kf40MbYgnd6v8Ehfx-T_cMqdxFlQCLA8GjmVuczruAdGdZIhW9lj6bG46P5cfB7W0FSxovPCBFhM-oCV2sOPue_aI-XRNFoYCJjNayFP12Z/s320/download_button.png&quot; title=&quot;Download Button&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;&lt;b&gt;Explanation Of The register.php&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;times new roman&amp;quot;;&quot;&gt;&lt;span style=&quot;font-size: medium;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;In
register.php, user is asked to enter his or her username, password
and confirm password. Then, we simply check username, password and
confirm password fields can not be left empty, if any of the field is
left empty then the user is informed to fill out that specific
detail.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;User
also needs to make sure that password and confirm password fields
have same values. If each field is filled out properly and the form
is submitted, &quot;User registered successfully!&quot; message is
displayed to the user.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: normal; margin-bottom: 0cm; margin-top: 0cm; text-align: left;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;&lt;b&gt;Explanation of login.php&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;font-style: normal; font-weight: normal; margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;In
login.php, user is asked to enter his or her username and password.
Then that credentials are checked with the pre-existing credentials
in the MySQL database. If a match is found then username is stored in
the session and user is redirected to the dashboard page. If no match
is found user is informed to register.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4 class=&quot;western&quot; style=&quot;font-style: normal;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;Explanation of dashboard.php&lt;/span&gt;&lt;/h4&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;font-style: normal; margin-bottom: 0cm;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;In
dashboard.php, it is checked to see if the user is already logged in
or not. It is done by checking if the session is not empty. But, if
it is found that user is not logged in, then the user is redirected
back to the login page.&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;font-style: normal; font-weight: normal; margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;Now,
the remaining functionality left is the logout functionality. The
code for logout is as following.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4 class=&quot;western&quot; style=&quot;font-style: normal;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;Explanation of logout.php&lt;/span&gt;&lt;/h4&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;font-style: normal; margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;To
implement the logout functionality, we need to start the session just
like we already did that in registration and dashboard pages. Next,
we need to destroy the session variable used to store the session
data and finally we destroy the entire session by calling destroy
function. Last but not the least, we redirect the user back to the
login page.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4 class=&quot;western&quot; style=&quot;font-style: normal;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;Bypassing
the Login Page&lt;/span&gt;&lt;/h4&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;font-style: normal; font-weight: normal; margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;We,
have completed creating the application. Now, let&#39;s see how to
exploit this application by bypassing the login page and gaining
access to the dashboard page.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZMQSJ5vZBHxOI3aKe_fWfGxfdYSk7Q5yaboLYxgeFxqd17RPBfbaot1BBocnF4-2hJnjnW3odADBfnQtoCbEheIXU0N6sWiN-0T9UmJ0kjOtWcA04l9auK2M1c0yGwsMOScRSDGX5gr0G/s1600/sql_inject_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Bypassing The Login Page&quot; border=&quot;0&quot; data-original-height=&quot;768&quot; data-original-width=&quot;1366&quot; height=&quot;358&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZMQSJ5vZBHxOI3aKe_fWfGxfdYSk7Q5yaboLYxgeFxqd17RPBfbaot1BBocnF4-2hJnjnW3odADBfnQtoCbEheIXU0N6sWiN-0T9UmJ0kjOtWcA04l9auK2M1c0yGwsMOScRSDGX5gr0G/s640/sql_inject_1.png&quot; title=&quot;Bypassing The Login Page&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Bypassing The Login Page&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: normal; font-weight: normal;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;As
shown in the above picture, if we type, &quot;&lt;span style=&quot;color: purple;&quot;&gt;&lt;b&gt;admin&#39;
or &#39;1&#39;=&#39;1&#39;;#&lt;/b&gt;&lt;/span&gt;&quot;
(without the double quotes) as username and any text in the password
field, we can bypass the login screen easily.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-style: normal; orphans: 2; text-align: left; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Explanation
Of How login bypass Works&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: normal; orphans: 2; text-align: left; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: normal; orphans: 2; text-align: left; widows: 2;&quot;&gt;
In username field what we wrote goes straight to the database engine in the following format.&lt;/div&gt;
&lt;div style=&quot;font-style: normal; orphans: 2; text-align: left; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: #a64d79;&quot;&gt;select
* from users where username=&#39;admin&#39; or &#39;1&#39;=&#39;1&#39;;# and password=&#39;1234&#39;
LIMIT 1;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;Here,
we wrote an expression that is always true (i.e, 1=1) and then &#39;or&#39;
operator is used to write that expression where either username is
admin or 1=1. As, always 1=1 is true so it does not matter to the
database engine if admin is not the username.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;After
the condition, the statement is terminated using the semicolon (;)
and rest of the statement that checks for password matching is
ignored as the hash symbol (#) is used.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: normal; orphans: 2; text-align: left; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-style: normal; orphans: 2; text-align: left; widows: 2;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div align=&quot;LEFT&quot; style=&quot;font-style: normal; margin-bottom: 0cm; orphans: 2; widows: 2;&quot;&gt;
&lt;span style=&quot;color: black; font-family: inherit;&quot;&gt;If
you like this post on&amp;nbsp;learning&lt;b style=&quot;font-weight: normal;&quot;&gt; sql injection step by step
part 1&lt;/b&gt;, please comment about what you think and share it with
others.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/sql-injection-part-1.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5M3x-L8lapa4e-9DUyDSuphRIUY9t5FTRMs-OGV0NTWq82EYQSjiFC6qpESPg3ubmzegOs1vU1jX60dEb2XGU3n-8U18_qXrfh04NqUYMOn621ohsK-KS-6JWFH8vdsDTE_N-bsXeSu-z/s72-c/app_login.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-7129425532225799174.post-8773018864840189406</guid><pubDate>Wed, 05 Jun 2019 06:18:00 +0000</pubDate><atom:updated>2023-03-08T16:10:50.163+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">general</category><title>Know All About SQL Injection In Depth</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;/h2&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;b&gt;SQL injection&lt;/b&gt; is a common attack technique used to attack a web application. I&lt;/span&gt;n this post, you will know different types of SQL injection attack in depth.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;After completely reading this post about SQL injection, you will have a clear concept about it in-depth.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3aWYWoyVx2o5dkvHfoxvqxrvXg-7oDuQb4KNru79a5FliDyy1mixUNMkEmGaDvecgvrq4ajBeD8_urspvn24uWppT_KerCeBlGsQYrhmpXrdhC6A8Kc91o0KACwrKy4f34rarqmawQJzP/s1600/sql-injection.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Sql Injection&quot; border=&quot;0&quot; data-original-height=&quot;1199&quot; data-original-width=&quot;800&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3aWYWoyVx2o5dkvHfoxvqxrvXg-7oDuQb4KNru79a5FliDyy1mixUNMkEmGaDvecgvrq4ajBeD8_urspvn24uWppT_KerCeBlGsQYrhmpXrdhC6A8Kc91o0KACwrKy4f34rarqmawQJzP/s320/sql-injection.jpg&quot; title=&quot;Sql Injection&quot; width=&quot;212&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;&lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;It&amp;nbsp;is an attack technique used to exploit applications by tricking a database engine in such a way so that it allows an attacker to view data that they are not normally able to retrieve. This might include data belonging to other users, or any other data that the application itself is able to access. In many cases, an attacker can modify or delete this data, causing persistent changes to the application&#39;s content or behavior.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;What are different types of SQL Injection ?&lt;/span&gt;&lt;/h2&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Union Based&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz-Em0XK3-vN9KmY2yN2y5wen_GxY8ju-L_mAx2NDock7BC7kfMvRIEMcFY7_QTlKrGTJH6OgtZh22NUV7iRFV3k4A1KcB2tWd40egsWSAhLzZBa9nP6SeYKINmOe6-Py0LEJVRHD9bwcb/s1600/union-injection.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Union Based Injection&quot; border=&quot;0&quot; data-original-height=&quot;225&quot; data-original-width=&quot;300&quot; height=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz-Em0XK3-vN9KmY2yN2y5wen_GxY8ju-L_mAx2NDock7BC7kfMvRIEMcFY7_QTlKrGTJH6OgtZh22NUV7iRFV3k4A1KcB2tWd40egsWSAhLzZBa9nP6SeYKINmOe6-Py0LEJVRHD9bwcb/s320/union-injection.png&quot; title=&quot;Union Based Injection&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Union Based Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;The &lt;b&gt;UNION&lt;/b&gt; operator is used to join multiple &lt;a href=&quot;https://en.wikipedia.org/wiki/SQL&quot; target=&quot;_blank&quot;&gt;SQL&lt;/a&gt; queries. An attacker can use this operator to create a query, so that the result of the new query will be joined to the result of the original query, allowing the attacker to execute multiple queries at once.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Error Based&amp;nbsp;&lt;/span&gt;&lt;/h3&gt;
&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6DkAVh00VsMiYlXMS95SG_F1DPi9LCedjAj19TfO76zWjY1JzBAqdnDUKLvqVNKxAN5iGzDIgpYtsDndl8aTctylG6a-tregOSEX-x3lWO5qU2cP1OHa4GFd5VYwbdiSGWD2XFMqb4JyH/s1600/error-based-injection.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: auto; margin-right: auto;&quot;&gt;&lt;img alt=&quot;Error Based Injection&quot; border=&quot;0&quot; data-original-height=&quot;1081&quot; data-original-width=&quot;1600&quot; height=&quot;432&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6DkAVh00VsMiYlXMS95SG_F1DPi9LCedjAj19TfO76zWjY1JzBAqdnDUKLvqVNKxAN5iGzDIgpYtsDndl8aTctylG6a-tregOSEX-x3lWO5qU2cP1OHa4GFd5VYwbdiSGWD2XFMqb4JyH/s640/error-based-injection.jpg&quot; title=&quot;Error Based Injection&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Error Based Injection&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this injection technique, the attacker relies on error messages generated by the database server to obtain information about the structure of the database. In some cases, this attack alone is enough for an attacker to enumerate an entire database.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Blind SQL Injection&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This technique is used when detailed error messages are not provided to the attacker. It is often the case, when the application displays user friendly error messages, with little or no technical error messages.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;This type of injection is divided into 2 types.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Boolean Based&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this type of attack the attacker creates SQL query such that after executing the query the result returned will be either true or false. Thereafter, by examining the outcomes of the true or false values, attacker understands that the application is vulnerable to this type of&amp;nbsp;attack. Then he or she uses that to further exploit the application.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;For example, suppose following web page displays a post detail having id equal to 2.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;http://www.example.com/post.php?id=2&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If a &lt;b&gt;SQL injection&lt;/b&gt; weakness is present, then executing following request on the web application:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;http://www.example.com/post.php?id=2+and+1=1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;should return the same web page as:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;http://www.example.com/post.php?id=2&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;It happens as the SQL statement &quot;&lt;span style=&quot;color: #cc0000;&quot;&gt;and 1=1&lt;/span&gt;&quot; is always true.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Executing the following request to a web application:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;http://www.example.com/post.php?id=2+and+1=0&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;would return a friendly error or no page at all. This happens because the SQL statement &quot;&lt;span style=&quot;color: #cc0000;&quot;&gt;and 1=0&lt;/span&gt;&quot; is always false.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Time Based&amp;nbsp;&lt;/span&gt;&lt;/h4&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;In this type of attack, the attacker constructs SQL query in such a way so that, if the query is successful then the database is forced to wait for some time (in seconds) before responding. If the query generates response after some time then attacker knows that the attack is successful.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;For example, if following request is sent to a web application:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394; font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;http://www.example.com/post.php?id=2-SLEEP(15)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;And if the page is displayed after some delay, then the application is vulnerable to time based attack.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;Final Words&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;verdana&amp;quot; , sans-serif;&quot;&gt;If you like this post as helpful, please do share and&amp;nbsp;comment your thoughts about it. Thank you!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</description><link>https://devhelperworld.blogspot.com/2019/06/sql-injection.html</link><author>noreply@blogger.com (Nilesh Sanyal)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3aWYWoyVx2o5dkvHfoxvqxrvXg-7oDuQb4KNru79a5FliDyy1mixUNMkEmGaDvecgvrq4ajBeD8_urspvn24uWppT_KerCeBlGsQYrhmpXrdhC6A8Kc91o0KACwrKy4f34rarqmawQJzP/s72-c/sql-injection.jpg" height="72" width="72"/><thr:total>0</thr:total></item></channel></rss>