Registered login module implemented with UNIX C system functions

Source: Internet
Author: User

1 /*login module, password placed in pass.db*/2#include <stdio.h>3#include <unistd.h>4#include <fcntl.h>5#include <stdlib.h>6#include <string.h>7#include <stdbool.h>8 9typedefstructperson{Ten     Charname[ -]; One     Charpass[ -]; A }person; -  - voidReg () the { -     Charname[ -]; -printf"Please input your name:"); -scanf"%s", name); +     intFD = open ("pass.db", o_creat| o_rdwr| O_append,0666); -     if(FD = =-1){ +printf"cannot open pass.db!\n"); AExit (-1); at     } -     intn =sizeof(person); -     CharTmp[n]; -     //determine if the user name exists -      while(Read (Fd,tmp,sizeof(person)) ==sizeof(person)) { -         if(!STRNCMP (Tmp,name, +)){ inprintf"This name had been registerwd!" -                     "Please try Anthor one!\n"); toprintf"Now please enter the name of you want:"); +scanf"%s", name); -Lseek (FD,0, Seek_set);//after entering the new name, start the comparison from the file header the         } *     } $printf"congratulations,%s is avilable!\n", name);Panax Notoginsengprintf"Now,please Enter the password:"); -     Charpass[ -]; the     Charcheck[ -]; +scanf"%s", pass); Aprintf"Check the password:"); thescanf"%s", check); +      while(strcmp (Pass,check)) { -printf"I ' m sorry,you entered different password!\n"); $printf"Please enter another password:"); $scanf"%s", pass); -printf"Check the password:"); -scanf"%s", check); the     } - Person Regperson;Wuyi strcpy (regperson.name,name); the strcpy (regperson.pass,pass); -Lseek (FD,0, seek_end); WuWrite (Fd,&regperson,sizeof(person)); - Close (FD); About } $  - voidconfirm () - { -     BOOLFlag =false; A     intFD = open ("pass.db", o_rdonly); +     if(FD = =-1){ theprintf"FILE \ "Pass.db\" opened failed\n"); -Exit (-2); $     } the Person tmp; the     Charname[ -]={0}; the     Charpass[ -]={0}; theprintf"\tname:"); -scanf"%s", name); in      while(Read (Fd,&tmp,sizeof(TMP)) ==sizeof(TMP)) { the         if(!STRNCMP (Name,tmp.name, -)){ the              while(STRNCMP (pass,tmp.name+ -, -)){ Aboutprintf"\tpassword:"); thescanf"%s", pass); the             } theFlag =true; +         } -     } the     if(flag)Bayiprintf"sucess!\n"); the } the  - intMain () - { theprintf"1,reg\t\t2,login\n"); the     int Select; thescanf"%d",&Select); the     Switch(Select){ -          Case 1: Reg (); the                 Break; the          Case 2: Confirm (); the                 Break;94         default:p rintf ("ERROR input\n"); the                  Break; the     } the     return 0;98}

Registered login module implemented with UNIX C system functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.