<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Joseph Chikeme on Medium]]></title>
        <description><![CDATA[Stories by Joseph Chikeme on Medium]]></description>
        <link>https://medium.com/@ojiofor?source=rss-6f6f7053ca87------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oEzC9cLzsfSs12qmuKmT6w.jpeg</url>
            <title>Stories by Joseph Chikeme on Medium</title>
            <link>https://medium.com/@ojiofor?source=rss-6f6f7053ca87------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 12:53:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ojiofor/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Angular Reactive Forms Strong Password Validation.]]></title>
            <link>https://medium.com/bitsrc/angular-reactive-forms-strong-password-validation-8dbcce92eb6c?source=rss-6f6f7053ca87------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dbcce92eb6c</guid>
            <category><![CDATA[form-validation]]></category>
            <category><![CDATA[reactive-forms]]></category>
            <category><![CDATA[angular-security]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Joseph Chikeme]]></dc:creator>
            <pubDate>Sun, 03 Sep 2023 20:36:11 GMT</pubDate>
            <atom:updated>2024-01-25T10:49:31.967Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular Reactive Form Strong Password Validation.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SC1QWMWiXk-60C7HZ0cn2A.jpeg" /></figure><p>In today’s digital age, ensuring the security of user accounts and data is paramount. One of the fundamental aspects of online security is having strong passwords. Weak passwords are an open invitation for malicious actors to compromise user accounts, potentially leading to significant data and security breaches. As developers, we are responsible for implementing strong password validation mechanisms to protect our users and their information. This article will explore how to implement strong password validation using Angular Reactive Forms.</p><h3>Why Strong Passwords Matter</h3><p>Before we dive into the technical details, let’s briefly discuss why strong passwords are essential:</p><ol><li><strong>Protecting User Accounts</strong>: Strong passwords are the first defense against unauthorized access. They make it significantly more challenging for hackers to guess or crack the password and gain access to an account.</li><li><strong>Preventing Data Breaches</strong>: Weak passwords are often the weakest link in a security chain. A single compromised account can lead to data breaches and security vulnerabilities affecting an entire system or organization.</li><li><strong>Compliance Requirements</strong>: Many regulatory bodies and industry standards (such as GDPR, HIPAA, and PCI DSS) require strong password policies to protect sensitive data.</li></ol><p>Let’s explore how to implement strong password validation in Angular Reactive Forms.</p><h3>Setting up Angular Reactive Forms</h3><p>Before implementing strong password validation, we need to set up Angular Reactive Forms in our application. If you haven’t already, you can import the necessary modules and initialize a form group in your component. Here’s a quick example:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { <br>  FormGroup,<br>  FormControl,<br>  Validators,<br>  ReactiveFormsModule, <br>} from &#39;@angular/forms&#39;;<br><br>@Component({<br>  selector: &#39;app-password-form&#39;,<br>  templateUrl: &#39;./password-form.component.html&#39;,<br>})<br>export class RegisterFormComponent {<br><br>constructor() {}<br>  <br>}</pre><h3>Implementing Strong Password Validation</h3><p>Let’s focus on implementing strong password validation in Angular Reactive Forms. We’ll use a combination of validators to enforce the following criteria for a strong password:</p><ol><li><strong>Minimum Length</strong>: A strong password should have a minimum length, typically at least 8 characters.</li><li><strong>Uppercase Letters</strong>: It should contain at least one uppercase letter.</li><li><strong>Lowercase Letters</strong>: It should contain at least one lowercase letter.</li><li><strong>Numbers</strong>: It should contain at least one number.</li><li><strong>Special Characters</strong>: It should contain at least one special character (e.g., !, @, #, $).</li></ol><p>Personally, I prefer to store my Regex in a separate file that I can export and share with other components.</p><pre>export const StrongPasswordRegx: RegExp =<br>  /^(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=\D*\d).{8,}$/;</pre><p>Note: Don’t encapsulate the Regex as a string to avoid unwanted bugs.</p><p>We will add our Regex to our Reactive form and a getter to access the password form control in the DOM easily.</p><pre>registerForm = new FormGroup({<br>    fullName: new FormControl&lt;string&gt;(&#39;&#39;),<br>    email: new FormControl&lt;string&gt;(&#39;&#39;),<br>    password: new FormControl&lt;string&gt;(&#39;&#39;, {<br>      validators: [Validators.required, Validators.pattern(StrongPasswordRegx)],<br>    }),<br>  });<br><br>get passwordFormField() {<br>    return this.registerForm.get(&#39;password&#39;);<br>  }</pre><h3>Providing User Feedback</h3><p>To provide meaningful feedback to users about the strength of their passwords, you can add error messages to your template and display them conditionally based on the form control’s validity. <br>Here’s an example:</p><pre> &lt;div class=&quot;text-red-400 text-sm&quot; *ngIf=&quot;passwordFormField?.dirty&quot;&gt;<br>    &lt;span class=&quot;block&quot; [ngClass]=&quot;{&#39;text-primary&#39;: passwordFormField?.value?.match(&#39;^(?=.*[A-Z])&#39;)}&quot;&gt;At least oneu ppercase<br>                            letter.&lt;/span&gt;<br>    &lt;span class=&quot;block&quot; [ngClass]=&quot;{&#39;text-primary&#39;: passwordFormField?.value?.match(&#39;(?=.*[a-z])&#39;)}&quot;&gt;At least one lowercase<br>                            letter.&lt;/span&gt;<br>    &lt;span class=&quot;block&quot; [ngClass]=&quot;{&#39;text-primary&#39;: passwordFormField?.value?.match(&#39;(.*[0-9].*)&#39;)}&quot;&gt;At least one<br>                            digit.&lt;/span&gt;<br>    &lt;span class=&quot;block&quot; [ngClass]=&quot;{&#39;text-primary&#39;: passwordFormField?.value?.match(&#39;(?=.*[!@#$%^&amp;*])&#39;)}&quot;&gt;At least one<br>                            special<br>                            character.&lt;/span&gt;<br>    &lt;span class=&quot;block&quot; [ngClass]=&quot;{&#39;text-primary&#39;: passwordFormField?.value?.match(&#39;.{8,}&#39;)}&quot;&gt;At least 8 characters<br>                            long.&lt;/span&gt;<br> &lt;/div&gt;</pre><p>As you can see, I checked if the password form field was dirty, displayed all the necessary password requirements, and then added a “text-primary” class to each span text when it passed the requirement.<br>You can also use the “hasError” form control method to check if the entire pattern failed, but I prefer this approach because it gives better feedback to the user.</p><h3>Conclusion</h3><p>Implementing strong password validation in Angular Reactive Forms is a crucial step in enhancing the security of your application. By enforcing password strength criteria, you help protect user accounts and sensitive data from potential threats. Remember that security is an ongoing process, and it’s essential to stay updated with best practices and adapt your password policies as security threats evolve. Strong passwords are just one piece of the security puzzle, but they are a critical one in today’s digital landscape.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dbcce92eb6c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/angular-reactive-forms-strong-password-validation-8dbcce92eb6c">Angular Reactive Forms Strong Password Validation.</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Confirm Password Validation in Angular with Custom Validators]]></title>
            <link>https://medium.com/bitsrc/implementing-confirm-password-validation-in-angular-with-custom-validators-6acd01cb0288?source=rss-6f6f7053ca87------2</link>
            <guid isPermaLink="false">https://medium.com/p/6acd01cb0288</guid>
            <category><![CDATA[custom-validation]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactive-forms]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[password-validation]]></category>
            <dc:creator><![CDATA[Joseph Chikeme]]></dc:creator>
            <pubDate>Tue, 30 May 2023 10:13:25 GMT</pubDate>
            <atom:updated>2025-03-04T17:39:33.967Z</atom:updated>
            <content:encoded><![CDATA[<h4>Create a custom validator in Angular to compare the password and confirm password fields and provide real-time feedback to the user.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCdAKMzD0zcQ4wOH8GbdVQ.jpeg" /></figure><p>When building secure web applications, one crucial aspect is ensuring that users provide the correct password during registration or when updating their account settings. Angular offers built-in validation features that make it easy to implement password confirmation functionality. In this blog post, we will explore how to create a custom validator in Angular to compare the password and confirm password fields and provide real-time feedback to the user.</p><blockquote>Also, check out <a href="https://blog.bitsrc.io/top-8-tools-for-angular-development-in-2023-a99d9f3a2e4e"><strong>some Angular dev tools you could try in 2023</strong></a>.</blockquote><figure><a href="https://bit.cloud/"><img alt="Build in AI speed — Compose enterprise-grade applications, features, and components" src="https://cdn-images-1.medium.com/max/1024/1*yX0vq3scSudyT61IuWFuEg.png" /></a><figcaption>Build in AI speed — Compose enterprise-grade applications, features, and components</figcaption></figure><p><strong>Step 1:</strong> Create a form group for the two password fields. <br>The trick here is validating the two password fields wrapped within a form group. My form group name is <strong>passwordForm </strong>which contains <strong>password1 </strong>and <strong>password2. </strong>You could name yours anything like <strong>password </strong>and <strong>confirmPassword </strong>or <strong>repeatPassword. </strong>It&#39;s all up to you<strong>.</strong></p><pre>import {<br>  FormControl,<br>  FormGroup,<br>  ReactiveFormsModule,<br>} from &#39;@angular/forms&#39;;<br><br>passwordForm: FormGroup = new FormGroup({<br>      password1: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      password2: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>  });</pre><p><strong>Step 2:</strong> Create a custom validator.<br>In Angular, validators are functions that take a form control as input and return an error object if the validation fails. Let’s create a custom validator to compare the password and confirm password fields. In your project, navigate to the src/app directory and create a new file called confirm-password.validator.ts or you can create it in the same typescript file as your form, but it’s better to dedicate a separate file for the custom validator because you can share this functionality with other components.</p><p>Add the following code (External file confirm-password.validator.ts above your component class):</p><pre>import {<br>  AbstractControl,<br>  ValidationErrors,<br>  ValidatorFn,<br>} from &#39;@angular/forms&#39;;<br><br>export const confirmPasswordValidator: ValidatorFn = (<br>  control: AbstractControl<br>): ValidationErrors | null =&gt; {<br>  return control.value.password1 === control.value.password2<br>    ? null<br>    : { PasswordNoMatch: true };<br>};</pre><p>Firstly, we created a function <strong>confirmPasswordValidator </strong>which returns a <strong>ValidatorFn. </strong>The confirmPasswordValidator returns a function of type <strong>ValidationErrors | null. </strong>ValidationErrors is an object containing the validation error arbitrary name and boolean to specify whether the error exists (In our case, true). Then <strong>null</strong> if there isn’t any error.</p><blockquote><em>💡</em> You can now encapsulate the confirm-password-validator module/function into its own component, and package, test, document, and publish it independently using <a href="https://bit.cloud/"><strong>Bit</strong></a><strong> </strong>so you (or others) can import it in any project with a simple bit import your.username/confirm-password-validator command.</blockquote><h4>Learn more:</h4><p><a href="https://bit.dev/docs/angular-components/components-overview/">Overview | Bit</a></p><p><strong>Step 3:</strong> Implement the Validator in a Form Now that we have our custom validator, let’s implement it in a form. Open the file and modify it as follows:</p><pre>import {<br>  FormControl,<br>  FormGroup,<br>  ReactiveFormsModule,<br>} from &#39;@angular/forms&#39;;<br><br>passwordForm: FormGroup = new FormGroup({<br>      password1: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      password2: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      { validators: confirmPasswordValidator }<br>  });</pre><p>or <br>If you have multiple validators for this form.</p><pre>import {<br>  FormControl,<br>  FormGroup,<br>  ReactiveFormsModule,<br>} from &#39;@angular/forms&#39;;<br><br>passwordForm: FormGroup = new FormGroup({<br>      password1: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      password2: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      { validators: [confirmPasswordValidator]}<br>  });</pre><p>or</p><p>If you prefer this syntax below, you can also wrap the validator in an array if you intend to use other validators. e.g. [confirmPasswordValidator, anotherValidator]</p><pre>import {<br>  FormControl,<br>  FormGroup,<br>  ReactiveFormsModule,<br>} from &#39;@angular/forms&#39;;<br><br>passwordForm: FormGroup = new FormGroup({<br>      password1: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      password2: new FormControl&lt;string&gt;(&#39;&#39;, [Validators.required]),<br>      confirmPasswordValidator<br>  });</pre><p>You don’t have to call the custom validation, except it expects an argument.</p><p><strong>Step 4: </strong>Display Validation Feedback To provide visual feedback to the user about the password confirmation validation, we can update the template file. Open the template file and modify it as follows:</p><pre>&lt;form [formGroup]=&quot;passwordForm&quot; (submit)=&quot;onSubmit()&quot;<br><br>  &lt;div&gt;<br>    &lt;label for=&quot;password1&quot;&gt;Password:&lt;/label&gt;<br>     &lt;input type=&quot;password&quot; id=&quot;password1&quot; formControlName=&quot;password1&quot;&gt; <br>  &lt;div&gt;<br>    &lt;label for=&quot;password2&quot;&gt;Confirm Password:&lt;/label&gt;<br>    &lt;input type=&quot;password&quot; id=&quot;password2&quot; formControlName=&quot;password2&quot;&gt;<br>    &lt;div class=&quot;error-message&quot; *ngIf=&quot;passwordForm.errors?.[&#39;PasswordNoMatch&#39;]&quot;&gt;<br>      Password does&#39;nt match.<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>  &lt;button type=&quot;submit&quot; [disabled]=&quot;passwordForm.invalid&quot;&gt;<br>&lt;/form&gt;</pre><p>You can use <strong>[ngClass]</strong> or <strong>[ngStyle]</strong> attribute directives to customize your form fields for a better user experience.</p><p>That’s it.✌🏾</p><h3>Build Angular Apps with reusable components, just like Lego</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*zsGaQykREEMqHUR0.png" /></figure><p><a href="https://bit.cloud/"><strong>Bit</strong></a><strong>’s open-source tool </strong>help 250,000+ devs to build apps with components.</p><p>Turn any UI, feature, or page into a <strong>reusable component</strong> — and share it across your applications. It’s easier to collaborate and build faster.</p><p><a href="https://bit.dev/docs/angular-introduction#-learn-angular-with-bit-">Introduction to Angular | Bit</a></p><p><strong>→ </strong><a href="https://bit.cloud/teambit/angular/content/angular-overview"><strong>Learn more</strong></a></p><p>Split apps into components to make app development easier, and enjoy the best experience for the workflows you want:</p><h3>→ <a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">Micro-Frontends</a></h3><h3>→ <a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">Design System</a></h3><h3>→ <a href="https://bit.cloud/blog/how-to-reuse-react-components-across-your-projects-l4pz83f4">Code-Sharing and reuse</a></h3><h3>→ <a href="https://www.youtube.com/watch?v=5wxyDLXRho4&amp;t=2041s">Monorepo</a></h3><h3>Learn more:</h3><ul><li><a href="https://bit.dev/blog/introducing-angular-component-development-environment-lfhd699k">Introducing Angular Component Development Environment</a></li><li><a href="https://blog.bitsrc.io/10-useful-angular-features-youve-probably-never-used-e9e33f5c35a7">10 Useful Angular Features You’ve Probably Never Used</a></li><li><a href="https://blog.bitsrc.io/top-8-tools-for-angular-development-in-2023-a99d9f3a2e4e">Top 8 Tools for Angular Development in 2023</a></li><li><a href="https://blog.bitsrc.io/getting-started-with-a-new-angular-project-in-2023-c6ae93facbd6">Getting Started with a New Angular Project in 2023</a></li><li><a href="https://blog.bitsrc.io/how-we-build-micro-front-ends-d3eeeac0acfc">How We Build Micro Frontends</a></li><li><a href="https://blog.bitsrc.io/how-to-share-angular-components-between-project-and-apps-5eb0600d99d2">How to Share Angular Components Between Projects and Apps</a></li><li><a href="https://blog.bitsrc.io/how-we-build-our-design-system-15713a1f1833">How we Build a Component Design System</a></li><li><a href="https://blog.bitsrc.io/creating-a-developer-website-with-bit-components-3f4083a7f050">Creating a Developer Website with Bit components</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6acd01cb0288" width="1" height="1" alt=""><hr><p><a href="https://medium.com/bitsrc/implementing-confirm-password-validation-in-angular-with-custom-validators-6acd01cb0288">Implementing Confirm Password Validation in Angular with Custom Validators</a> was originally published in <a href="https://medium.com/bitsrc">Bits and Pieces</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use Angular CanActivate(CanActivateFn) function.]]></title>
            <link>https://medium.com/@ojiofor/how-to-use-angular-canactivate-function-b153e5a79f51?source=rss-6f6f7053ca87------2</link>
            <guid isPermaLink="false">https://medium.com/p/b153e5a79f51</guid>
            <category><![CDATA[angular-inject]]></category>
            <category><![CDATA[angular-16]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[angular-guards]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Joseph Chikeme]]></dc:creator>
            <pubDate>Mon, 22 May 2023 20:03:29 GMT</pubDate>
            <atom:updated>2023-05-22T20:06:49.852Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I updated my Angular project from version 14 to version 16. I had a couple of bugs due to some updates in the recent Angular 16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*63BlrZrARsPkNv9Cgc0lSA.jpeg" /></figure><p>Today, I’ll share how I transitioned from my CanActivate class to using the CanActivate(CanActivateFn) function.</p><p>This was my CanActivate class-based code.</p><pre>export class AuthGuard implements CanActivate {<br><br>constructor(private token: TokenService, private router: Router) { }<br><br>canActivate(<br> route: ActivatedRouteSnapshot,<br> state: RouterStateSnapshot): <br> Observable&lt;boolean | UrlTree&gt; <br> | Promise&lt;boolean | UrlTree&gt; <br> | boolean <br> | UrlTree {<br> return this.token.authenticated.pipe(take(1), map(status =&gt; {<br><br> if (!status) {<br> return this.router.createUrlTree([&#39;/login&#39;])<br> }<br> return true<br> }))<br><br> }</pre><p>My current CanActivate code looks like this.👇🏾</p><pre>export const AuthGuard: CanActivateFn = (<br>  route: ActivatedRouteSnapshot,<br>  state: RouterStateSnapshot<br>):<br>  Observable&lt;boolean | UrlTree&gt; <br>  | Promise&lt;boolean | UrlTree&gt; <br>  | boolean <br>  | UrlTree=&gt; {<br><br>  return inject(TokenService).authenticated()<br>    ? true<br>    : inject(Router).createUrlTree([&#39;/auth/login&#39;]);<br><br>};</pre><p>This code is slimmer and more readable. 😊<br>If you noticed, I didn’t pipe or subscribe to the service. That’s because I updated my service to use <a href="https://angular.io/guide/signals">Signals</a>, another nice feature added in Angular 16.</p><p>Then, I used the<strong> Inject() </strong>function to load my <strong>Token Service; </strong>finally, I used a ternary operator because I noticed how cool it’d look, given that the logic is straightforward.</p><p>Then, add your new AuthGuard function to the CanActivate route array without parenthesis.</p><pre>const routes: Routes = [<br>  {<br>    path: &#39;&#39;,<br>    component: DashboardComponent,<br>    canActivate: [AuthGuard],<br>  }</pre><p>That’s all. 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b153e5a79f51" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>