DOWNLOAD C++ CODE FOR PASSWORD SHOWN AS STARS



INPUT PASSWORD IN THE FORM OF STARS CODE WRITTEN IN C++:
This is code written in the programming language C++ which ask the user to enter the password on the console and password is shown as stars on the screen.You can download this code by clicking the download button below or you can copy paste.


HAPPY CODING!


#include <iostream>
#include<string>
#include<windows.h>

using namespace std;

int CheckKeyPressed(int waitTime)
{
    HANDLE h= GetStdHandle(STD_INPUT_HANDLE);
    INPUT_RECORD r;
    DWORD w = 1;
    DWORD eventss;
    DWORD waitResult=0;
    int keypressed = false;
    int toReturn = 0;

    waitResult = WaitForSingleObject(h,waitTime);

    if (waitResult == WAIT_OBJECT_0)
    {
        //FlushConsoleInputBuffer(h);..commented out as this takes to asynchronous mode on some systems
        keypressed = ReadConsoleInput(h,&r,1,&eventss);

        if (keypressed && r.EventType==KEY_EVENT && r.Event.KeyEvent.bKeyDown)
            toReturn = r.Event.KeyEvent.wVirtualKeyCode;
        //this should make sure that checkKeyPressed is not called twice for arrow keys
        if (toReturn == 224)
            toReturn = CheckKeyPressed(waitTime);


        FlushConsoleInputBuffer(h);
    }
    return toReturn;
}


char return_char(int a)
{
    char ch;

         if (a==65) ch='a';
    else if (a==66) ch='b';
    else if (a==67) ch='c';
    else if (a==68) ch='d';
    else if (a==69) ch='e';
    else if (a==70) ch='f';
    else if (a==71) ch='g';
    else if (a==72) ch='h';
    else if (a==73) ch='i';
    else if (a==74) ch='j';
    else if (a==75) ch='k';
    else if (a==76) ch='l';
    else if (a==77) ch='m';
    else if (a==78) ch='n';
    else if (a==79) ch='o';
    else if (a==80) ch='p';
    else if (a==81) ch='q';
    else if (a==82) ch='r';
    else if (a==83) ch='s';
    else if (a==84) ch='t';
    else if (a==85) ch='u';
    else if (a==86) ch='v';
    else if (a==87) ch='w';
    else if (a==88) ch='x';
    else if (a==89) ch='y';
    else if (a==90) ch='z';

return ch;
}

int main()
{
    string password;
    bool condition=true;
    int i=0;


cout<<"Enter the password:";

  while (condition==true)
  {//start while
   char c;

  int a=CheckKeyPressed(0);

      if (a==13)
      condition=false;

    else if (a>=65 && a<=90)
      {
        c=return_char(a);
        password=password+c;
        cout<<"*";
        }

  }//end while

  cout<<endl<<endl<<"Password entered:"<<password;

    return 0;

}







  DOWNLOAD CODE WITH EXECUTABLE FILE:





No comments:

Post a Comment