C Programming Tutorial - 33 - isupper and Challenge #1!

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thank you so much! I couldn't believe myself that I finally have been able to complete this challenge. After trying for two days I finally did it. You are a great teacher, man!

coderAsif
Автор

This is an easy to understand and effective code so far. Widely open for criticism though and every thing we've learned so far

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
char password [50];
int i;
int low = 0;
int high = 0;
int dig = 0;

printf("Please enter a strong password! \n");
printf("your password should contain \n");
printf("upper case letters, small case letters and numbers. \n");

scanf(" %s", &password);

for (i = 0; i < 50; i++)
{
if (islower(password[i]))
{
low = 1;
break;
}

}

for (i = 0; i < 50; i++)
{
if (isupper(password[i]))
{
high = 1;
break;
}

}

for (i = 0; i < 50; i++)
{
if (isdigit(password[i]))
{
dig = 1;
break;
}
}

if ((low * high * dig) != 0)
{
printf("You have entered a strong password. \n");

}

else
{
printf("You have entered a weak password. \n");
}

}

abelashenafi
Автор

For all of those who are studying programming, take a look at all these codes. Notice how unique they are. Look at the variable names, setup, and comments. Appreciate the different minds who tackle problems in their own understanding. Who knows, you may just learn something new. :) Plus, it's easy to spot plagiarism

skylarkenneth
Автор

LOVE these tutorials, thank you Bucky!

yingtang
Автор

This challenge was easy, but for a beginner it could be a challenge because he hasn't shown us how to iterate through an array at this point. Don't feel bad if you couldn't figure this out! Here is my solution:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main() {
int pass, upper, digi, dollar, i, len = 0;
char password[20];

printf("Enter your password (Must contain uppercase letter, number, and dollar sign)\n");
scanf("%s", &password);
len = sizeof(password);


for(i = 0; i < len; i++) {
if (isupper(password[i])){
upper = 1;
}
if (isdigit(password[i])){
digi = 1;
}
if (password[i] == '$'){
dollar = 1;
}
}
if(upper>0 && digi>0 && dollar>0 ){
printf("Well done, you entered a correct password");
}else{
printf("You Messed up");
}

return 0;
}

Numenorean
Автор

For anyone that's stuck, this is the code I used to tackle the challenge.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main(void){
char password[50];

printf("Enter password: ");
scanf("%s", password);

int passwordLength = strlen(password);
int upperChar = 0;
int lowerChar = 0;
int specialChar = 0;
int isNumber = 0;
int minLength = 8;

// Loop checking for password minimum requierments.
if(passwordLength > minLength){
for(int i = 0; i < passwordLength; i++){
if(isalpha(password[i])){
if(isupper(password[i])){

}else{

}
}else{
if(isdigit(password[i])){

}else{

}
}
}
}else{
printf("Password to short, minimum %d\n.", minLength);
}

// Letting user know if password is correct or what's missing.
if(upperChar && specialChar && isNumber && (passwordLength > minLength)){
printf("Password set!\n");
}else{
if(!upperChar){
printf("Password needs to include a uppercase letter.\n");
}else if(!specialChar){
printf("Password needs to include a special character.\n");
}else{
printf("Password needs to include a number.\n");
}
}

// Extra details about the password
details:\n");
printf("Upper: %d, Lower: %d, Special: %d, Numbers: %d, Length: %d",
upperChar, lowerChar, specialChar, isNumber, passwordLength);

return 0;
}

danielmaslany
Автор

Always interesting to see what crazy times you are recording these at xD

ewanlister
Автор

Bucky as a novice programmer you are killing me but i like it :)

realdolantrump
Автор

I know nothing about programming sans all the previous C tutorial vids (HTML5 aint programming) before this one, therefore i am not surprised it took me half an hour to learn that my only error was that I mistyped and replaced an 'i' with a '1'. Thanks a bunch (no seriously, my classes starts in a week from the moment im typing this, and all the fellow freshmen of my college course knows something.



#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

//Checking if an inputted password is strong (Must have at least one small letter, one capital letter, one number, and one character symbol).

int main()
{
char Password [30]; int i; int LowCaseChar = 0; int HighcaseChar = 0; int Number = 0; int NonAlphanumericChar = 0;
printf("Please enter your password:\t"); scanf(" %s", Password);

for (i = 0; i < 29; i++){
if(isalpha(Password[i])){
if(isupper(Password[i])){
HighcaseChar++; continue;
}else if(islower(Password[i])){
LowCaseChar++; continue;
}
}else if(isdigit(Password[i])){
Number++; continue;
}else{
NonAlphanumericChar++; continue;
}
}

if(LowCaseChar != 0 && HighcaseChar != 0 && Number != 0 && NonAlphanumericChar != 0){
printf("\nYour password is strong.\n\n");
}else{
printf("\nYour password is weak.\n\n");
}

return 0;
}

conficturaincarnatus
Автор

Thanks man! great tutorials! really good! very clear in every sense! explanation and also your type of american accent.

saras
Автор

This code is a little longer, but allows you to enter any symbol instead of just the $. It also allows any password length up to 99 characters and tells you what you messed up.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main()
{

    int a, b; //These are the character position and character count for the password respectively
    int upperYes, lowerYes, numberYes, symbolYes; //These are my check variables
    char password[99]; //This is obviously the password string

    while(0==0){
    a=0; //Since a is the veriable I use to determine which character I am observing, it must begin as a 0 each time
    //In order to reset the variables before checking for a password
    printf("Enter a password with at least 1 each upper and lower case letters, numbers, and symbols\n");
    scanf(" %s", &password);

    for(b=0; password[b]!='\0'; b++){} //This quick loop will set b to the number of characters in password
    do{
        if(isalpha(password[a])){
            if(isupper(password[a])){
                upperYes = 1;
                a++;
            }else {
            lowerYes = 1;
            a++;}
        }else {if(isdigit(password[a])){
                numberYes=1;
                a++;}else {
                    symbolYes=1;
                    a++;}}
    }while(a<=(b-1)); //(b-1) simply because the computer counts from 0

    printf("%d %d %d %d\n", upperYes, lowerYes, numberYes, symbolYes); //This extra line lets me check which of my variables are actually resetting properly

    if(lowerYes==1 && upperYes==1 && numberYes==1 && symbolYes==1){
        printf("\nYour password has been set\n");
        break;
    }else {
    printf("\nYour password is incorrect\n");}

    if(lowerYes!=1){
        printf("You need a lower case letter\n");
    }
    if(upperYes!=1){
        printf("You need an upper case letter\n");
    }
    if(numberYes!=1){
        printf("You need a number\n");
    }
    if(symbolYes!=1){
        printf("You need a symbol\n");
    }
    }


    return 0;
}

themessiahcensored
Автор

Finally able to do it, thank you so much for your tutorial.
this is my attempt

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
int main()
{
char password[20];
int testA, testB, testC; //test = which letter will be scanned.
int result1, result2, result3;

printf("Please enter your password:\n"); //user enter password.
printf("[Must contain one uppercase and one digits.]\n");
scanf("%s", &password); //scan for password.

for(testA=0 ; testA<=20 ;testA++){ //for loop (initial value ; limit value ; action)

if( isupper(password[testA])){ //password[test1], test1 will be replace with number when looping
result1 = 1; //if one of the character is uppercase, result1 will equal to 1
}}

for(testB=0 ; testB<=20 ;testB++){ //same thing for test B and testC, test for digit and lowercase.

if( isdigit(password[testB])){
result2 = 1;
}}

for(testC=0 ; testC<=20 ;testC++){

if( islower(password[testC])){
result3 = 1;
}}

if(result1 + result2 + result3 == 3){ //equal to 3 = met all criteria.
printf("Great Password!\n");
}else{
printf("Your password must contain at least one upper cast and one digit\n");
}



return 0;
}

lychee
Автор

Just starting out with C.. Here is my version.. Basically asks to Enter the correct password again if the password is incorrect.. Thanks Bucky.. Even after 6 yrs your vids are really helping..


#include <stdio.h>
#include <stdlib.h>

int main()
{
int j;
int i;
int upperCase, number, symbol, correct;
char password[20];

do{
upperCase = number = symbol = correct = 0;

printf("Please Enter password: ");
scanf("%s", password);

for
if(isalpha(password[i]) && isupper(password[i])){
upperCase =1;
}else if(isdigit(password[i])){
number = 1;
}else if (!isalpha(password[i]) && !isdigit(password[i])){
symbol = 1;
}
}
correct = upperCase+number+symbol;

if (correct<3){
printf("Password needs to have atleast 1 number, 1 uppercase & 1 symbol\n");
j=1;
} else {
printf("Congratulations, Password is correct");
j=0;
}
}while(j==1);

return 0;
}

abby
Автор

Hey fellow Coders and Codesses! I finally got this to work. Here is my code:

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main()
{
char password[50];
int i;
int upper = 0;
int number = 0;
int dollarSign = 0;

//ask the user to input a password containing an uppercase letter and number and $ sign

printf("Please enter a password containing an Uppercase letter, a number and a $ sign: ");
scanf(" %s", password);

i = strlen(password);
printf("length of string = %d\n", i);

//now we check if the password given contains an uppercase letter, a number and a $ sign

for( i = 0; password[i] != 0; i++)
{
if ( isalpha(password[i]))
{
if( isupper(password[i]))
{
upper += 1;
printf("Your password contains an Uppercase letter: %c\n", password[i]);
break;
}
}
}

for( i = 0; password[i] != 0; i++)
{
if ( isdigit(password[i]))
{
number += 1;
printf("Your password contains a number: %c\n", password[i]);
break;
}
}

for( i = 0; password[i] != 0; i++)
{
if (password[i] == '$')
{
dollarSign += 1;
printf("Your password contains a dollar sign: %c\n\n", password[i]);
break;
}
}

//now we give the user final feedback on whether their password is acceptable or not

if ( (upper == 1) && (number == 1) && (dollarSign == 1) )
{
printf("You have a strong password!\n");
}
else
{
printf("Your password sucks!\n");
}

return 0;
}

jolenevanree
Автор

If you are needing help, here's a simple code:

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>



int main(){



char pw[7];
//Password is set to be an array with 8 characters max
int upper = 0;

int lower = 0;

int digit = 0;




scanf(" %s", pw);



for(int i=0; i<8; i++){

//now check if the password entered meets all requisites
through checking and incrementing the respective variable
if(isupper(pw[i])){

upper++;

continue;

}

else if(islower(pw[i])){

lower++;

continue;

}

else if(!isdigit(pw[i])){

digit++;

continue;

}

}

//Tells the user if the password he entered is good to go or not

if(lower && upper && digit){

printf("Well done...");

}



else{

printf("Try again...");

}



}

luizalmeida
Автор

Hi everyone! This is my 2nd day of watching Bucky's C programming tutorial. So far I'm having so much fun learning C. This is my solution to the challenge.

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

int main() {

char password[20];
printf("This Program will record your password\n");
printf("Make sure the first 3 characters is either\n");
printf("An Uppercase letter, a number and a letter\n");
printf("\n\nEnter your password: ");
scanf(" %s", password);


&&
&&
((password[0] == '$')||(password[1] == '$')||(password[2] == '$'))
)
{
printf("Verified!\n");

}else{
printf("Not Verified!");
}


return 0;
}

P.S.
As i was writing this code. I was thinking if its possible to answer this challenge by checking every characters in the password.
ex.
th3pas$worD = verified
if so, how? or maybe i should carry on and watch more of Bucky's tutorial then i might have the answer.
Anyway, if there is an area to improve in my code. please let me know. it would be much appreciated. thanks. have a nice day!

jeffreyarias
Автор

Very simple and easy to understand :)


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main()
{

char password[20];

int i, lower, upper, digit;
lower=upper=digit=0;

do{
lower=digit=upper=0;
printf("Enter Strong Password \t\t [L:%d] [U:%d] [D:%d]\n >", lower, upper, digit);
scanf(" %s", password);


{



}

printf("[L:%d] [U:%d] [D:%d]\n\n\n", lower, upper, digit);

}while((upper && lower && digit) !=1 );

printf("\nPassword Set.\n");
return 0;
}

mohamedkhaled-hkxv
Автор

Hey guys this is my version of the challenge. Do let me know if I've missed something
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
int main()
{
int i, j, k, s, len;
char password[20];
printf("Enter your password:\n");
scanf(" %s", password);
len=strlen(password);
for(i=0;i<len;i++)
{
if(isdigit(password[i]))
{
break;
}
else if(i==len-1)
{
printf("Invalid Password\n");
exit(1);
}
else
{
continue;
}
}
printf("Has a digit\n");
for(j=0;j<len;j++)
{
if(isalpha(password[j]))
{
if(isupper(password[j]))
{
break;
}
}
else if(j==len-1)
{
printf("Invalid Password\n");
exit(1);
}
else
{
continue;
}
}
printf("Has an upper case letter\n");
for(k=0;k<len;k++)
{
if(isalpha(password[k]))
{
if(islower(password[k]))
{
break;
}
}
else if(k==len-1)
{
printf("Invalid Password\n");
exit(1);
}
else
{
continue;
}
}
printf("Has a lowercase letter\n");
for(s=0;s<len;s++)
{
if(password[s]=='$')
{
break;
}
else if(s==len-1)
{
printf("Invalid Password\n");
exit(1);
}
else
{
continue;
}
}
printf("Has a special character $\n");
printf("Valid Password\n");


return 0;
}

syedareeb
Автор

Here is something, the code will keep asking you to enter while keeping track of your attempts until you get something right.

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>

int main() {

int lp = 64;
char password[lp];
int has_uppercase = 0;
int has_lowercase = 0;
int has_number = 0;
int has_syntax = 0;
int i = 0;
int try = 1;
printf("A strong password has upper and lower case letters, numbers, and syntax. \n");
while(try!=0){
printf("Enter a strong password : ");
scanf(" %s", password);

const char * z = password;
int m;
int charcount = 0;

for(m=0;z[m];m++){
if(z[m]!= ' '){
charcount ++;
}
}

for(i=0;i<charcount;i++){

char current_char = password[i];

if(isdigit(current_char)) {
has_number++;
}else if(islower(current_char)) {
has_lowercase++;
}else if(isupper(current_char)){
has_uppercase++;
}else if(isprint(current_char)){
has_syntax++;
}else if(has_number!=0 && has_lowercase!=0 && has_uppercase!=0 && has_syntax!=0){
break;
}
}

if(has_uppercase==0 || has_lowercase==0 || has_number==0 || has_syntax==0) {
printf("Password not strong enough, Try Again!\n Attempt %d \n", try);
i = 0;
try++;
}else{
printf("nice secure password\n");
try = 0;
}
}
return 0;
}

promefius
Автор

My attempt, with comments:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
char password[20]; // Char array that will store user's password, max of 20 characters.
int numA, numB, numC; // Used to test different conditions,
// i.e. upper case or numbers

printf("Please enter a password : "); // Prompts the user to enter a password so that it can be tested.
scanf("%s", &password); // Reads the input entered by the user.

for (numA = 0; numA < 20; numA++) // Loop iterates 20 times, reading each character in the char array.
{
if (isalpha(password[numA] && isupper(password[numA]))) // Functions to check if a character is a letter and if it's upper case.
continue; // If the above conditions are true, the loop moves to the next character.
else if (isalpha(password[numA]))
break; // If the character is only a letter, not upper case, the loop terminates.
}

for (numB = 0; numB < 20; numB++) // Loop iterates 20 times, reading each character in the char array.
{
if (isupper(password[numB])) // If the current character is upper case then the loop terminates.
break;
}

for (numC = 0; numC < 20; numC++) // Loop iterates 20 times, reading each character in the char array.
{
if (isdigit(password[numC])) // If the current character is a digit then the loop terminates.
break;
}

if (numA < 20 && numB < 20 && numC < 20) // If all conditions have been met, and the combined values are less than 20
// (size of the array). Then the program outputs a message to the user saying that
// they have a good password.
printf("\nPassword is good");
else
printf("\nPassword is not good"); // Othereise an error message is output.

getch();

return 0;
}

dannutt
join shbcf.ru