C language script: Compare 2 passwords


This script asks user to input password 2 times, and checks if the input is same both times.

#include <stdio.h>
#define SIZE 15

/*  check_passwd function prototype */

char check_passwd (char [],char []);
/* main function */

int main (void) {

char passwd1[SIZE], passwd2[SIZE], ch;

   printf("\nPlease enter password [max %d char]: ", SIZE);
   scanf("%s",passwd1);
   printf("\nPlease confirm your password [max %d char]: ", SIZE);
   scanf("%s",passwd2);

ch=check_passwd(passwd1,passwd2);

if (ch == 'A')
 printf("\nThank you! Your password is being saved!");
 else {
         printf("\nUnfortunately your passwords do not match!\n");
         printf("\nWrong letter << %c >>\n", ch);
 }
return 0;
 }

/* function check passwd */
char check_passwd (char passwd1[],char temp[]){
  int i;

     char ch = '+';
    for (i=0;passwd1[i] != '';i++){


  if (passwd1[i] != temp[i])
        ch=temp[i];
   }

if (ch == '+')
       return 'A';
 else
       return ch;
}
Advertisements

About Anatoly Spektor

My name is Anatoly Spektor (originally Anatolijs Spektors) I am Software and Web Developer. I have worked in Seneca Center for Development of Open Technology on Big Blue Button Add-on - Polling Module, Red Hat and some other places :) I am an author of the book 'Eclipse Debugging How To', Muay Thai fighter and amateur photographer ;)
This entry was posted in Programming Languages. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s