Sei sulla pagina 1di 42

Authentication System(AS)

Software Design Document

ARICENT: Draft Version: 0.1

Copyright 2006-2011 The Aricent Group. All Rights Reserved. No part of this ocument ma! "e repro uce # store in a retrie$a% s!stem# istri"ute or transmitte # in an! form# or "! an! means# e%ectronic or otherwise# inc%u ing photocop!ing# reprinting# or recor ing# for an! purpose# without the e&press prior written permission of The Aricent 'roup. Printed in ________ TRA !"AR#$% Aricent an the Aricent (ogo are mar)s an registere tra emar)s of The Aricent 'roup in the *.S. an certain other countries. The use of these tra emar)s without Aricent+s prior written consent is strict%! prohi"ite . ,ther thir part! tra emar)s reference are the propert! of their respecti$e owners. -%ease note that the a"o$e %ist is not a%%.inc%usi$e# an the a"sence of an! mar) from this %ist oes not mean that it is not an Aricent tra emar). &$C'A&"!R The information in this "oo) is pro$i e /AS . IS0# without warrant! of an! )in # e&press or imp%ie # inc%u ing "ut not %imite to a warrant! of merchanta"i%it!# fitness for an! particu%ar purpose# tit%e or non.infringement of thir part! rights# an Aricent specifica%%! isc%aims a%% other warranties# con itions or representations. This ocument is pro$i e for informationa% purposes on%!# an shou% not "e construe as a representation or a commitment on the part of Aricent. Information in this ocument is su"1ect to change without notice.

R!()!$T$ 2or information re3uests or for o"taining permission for the use of this wor)# p%ease su"mit a written re3uest to: Corporate 4ar)eting an (ega%# The Aricent 'roup# ,ne Tower Center 5ou%e$ar # 16th 2%oor# East 5runswic)# N7 06618# *SA. *C)"!+T +o.% AR&C!+T%

R!,&$&*+ -&$T*R.
Revision No. 0.1 Date Description of Change Draft 0.1 Author Shagun# Vasu ha 'o)ha%e# Ar$in Sharma# Amantu%%ah Af9a%# Sa%im 7a$e Reviewed & Approved By Rashi Arora

Contents
C A!"#R $% 1. &+TR* )CT&*+________________________________________________/ 1.1 -*R-,SE....................................................................................................... : 1.; SC,-E........................................................................................................... : 1.< DE2INITI,NS AND ACR,N=4S..........................................................................: 1.<.1 Definitions.................................................................................................. : 1.<.; Acron!ms.................................................................................................. 6 1.> RE2ERENCES................................................................................................. 6 1.? D,C*4ENT ,R'ANISATI,N.............................................................................6 1.8 A--R,VA(S AND A*T@,RIAATI,NS..................................................................6 1.: DISTRI5*TI,N................................................................................................ 6 2. -&G- '!,!' !$&G+___________________________________________0 ;.1 (EVE( 0 DESI'N DESCRI-TI,N.......................................................................B ;.1.1 Interface Description ..............................................................................10 ;.; (EVE( 1 DESI'N DESCRI-TI,N ....................................................................10 ;.;.1 4o u%e name: Authentication S!stemC(e$e%.0D.......................................11 ;.;.1.1 Decomposition Description.........................................................11 ;.;.1.1.1 4o u%e Description................................................................11 ;.;.1.; Depen enc! Description............................................................1; ;.< (EVE( ; DESI'N DESCRI-TI,N ....................................................................1< ;.<.1 4o u%e name: InputC(e$e%.1D...................................................................1< ;.<.1.1 Decomposition Description.........................................................1< ;.<.1.1.1 4o u%e Description................................................................1< ;.<.1.; Depen enc! Description...........................................................1> ;.<.; 4o u%e name: Authentication C(e$e%.;D...................................................1? ;.<.;.1 Decomposition Description.........................................................1? ;.<.;.1.1 4o u%e Description................................................................18 ;.<.;.; Depen enc! Description............................................................1: ;.> STR*CT*RE DIA'RA4...........................................................................1: ;.>.1 Structure name: *SER............................................................................1: ;.>.; Structure name: SERVER.......................................................................16 ;.>.< Structure name: threa Efun.....................................................................1B 1. A'T!R+AT! !$&G+ __________________________________________10 <.1 A(TERNATE DESI'NS...................................................................................1B <.; DESI'N EVA(*ATI,N RE-,RT ;0 <.< DESI'N (I4ITATI,NS....................................................................................;0 2. !TA&'! !$&G+____________________________________________20 >.1 Detai%e Data Design ...............................................................................;0 Ta"%e >.1.1: Data Design for 'enera% 4acros.................................................;1 Ta"%e : >.1.; Design for Error @an %ing 4acros..............................................;; ERR,R @AND(IN' 4ACR,S............................................................;; NA4E ;; DESCRI-TI,N.................................................................................;; VA(*E ;; 2I(EEN,TE,-EN.............................................................................;; If there is error opening a fi%e...............................................................;; 0 ;; 2I(EEN,TEC(,SE...........................................................................;; If there is error c%osing a fi%e.................................................................;;
1

C A!"#R &%

C A!"#R '%

C A!"#R (%

S)*"+AR# D#S,-N D)C./#N" AR,C#N" C)N*,D#N",A0

1 ;; *NEF-ECTEDEE,2.........................................................................;; If a fi%e reaches en of fi%e une&pecte %!.................................................;; ; ;; 4E4,R=E2AI(*RE..........................................................................;; If memor! is not a%%ocate ...................................................................;; < ;; READEERR,R.................................................................................;; If there is error in rea ing....................................................................;; > ;; GRITEEERR,R...............................................................................;; If there is error in writing.....................................................................;; ? ;; RECEIVEEC(IENT............................................................................;; If there is an error in recei$ing from c%ient...............................................;; 8 ;; RECEIVEESERVER..........................................................................;; If there is error in recei$ing from ser$er..................................................;; : ;; SENDEC(IENT.................................................................................;; If there is error in sen ing to c%ient........................................................;; 6 ;; SENDESERVER...............................................................................;; If there is erro in sen ing to ser$er........................................................;; B ;; >.1.1 Data Structure:Structure for user etai%s.................................................;< >.1 DETAI(ED 4,D*(E DESI'N ..........................................................................;>

S)*"+AR# D#S,-N D)C./#N" AR,C#N" C)N*,D#N",A0

*igures
2igure ;.1 : (e$e% 0 D2D: Conte&t Diagram HHHHHHHHHHHHHHHHHHHHHHHHHHH..0B 2igure ;.; : (e$e% 1 D2D: Conte&t Diagram HHHHHHHHHHHHHHHHHHHHHHHHHHH..10 2igure ;.<.1 : (e$e% ; D2D: Conte&t DiagramHHHHHHHHHHHHHHHHHHHHHHHHHHH1< 2igure ;.<.; : (e$e% ; D2D: Conte&t DiagramHHHHHHHHHHHHHHHHHHHHHHHHHHH1? 2igure ;.>.1 : Structure DiagramCuserD HHHHHHHHHHHHHHHHHHHHHHHHHHHHH..1: 2igure ;.>.1 : Structure DiagramCser$erDHHHHHHHHHHHHHHHHHHHHHHHHHHHHH16 2igure ;.>.1 : Structure DiagramCthrea EfunD..HHHHHHHHHHHHHHHHHHHHHHHHHH..16

S)*"+AR# D#S,-N D)C./#N" AR,C#N" C)N*,D#N",A0

"a12es

C A!"#R 3% C A!"#R 4% C A!"#R 5% C A!"#R 6% C A!"#R 7% C A!"#R $8% C A!"#R $$% C A!"#R $&%

TA3'! 1-1% !4&+&T&*+$ )$! TA3'! 1-1% !4&+&T&*+$ )$! TA3'! 1-2% ACR*+."$ )$! TA3'! 1-2% ACR*+."$ )$! TA3'! 1-1% APPR*,A'$ A+ TA3'! 1-1% APPR*,A'$ A+

&+ T-&$ &+ T-&$ &+ T-&$ &+ T-&$

*C)"!+T___________________/ *C)"!+T___________________/ *C)"!+T____________________5 *C)"!+T____________________5

A)T-*R&6AT&*+$_____________________5 A)T-*R&6AT&*+$_____________________5

TA3'! 1-2% &$TR&3)T&*+________________________________________5 TA3'! 1-2% &$TR&3)T&*+________________________________________5

S)*"+AR# D#S,-N D)C./#N" AR,C#N" C)N*,D#N",A0

Chapter

$
1.,ntroduction 1.1 !urpose
To imp%ement an Authentication S!stem# which isp%a!s a fi%e to the authenticate user.

1.2 Scope
AS imp%ementation ena"%es the user to $iew a fi%e present on the s!stem# if heIshe is authenticate to $iew that fi%e. AS s!stem registers new user an store the user etai%s in ata "ase "! using appropriate encr!ption a%gorithm to store the passwor .

1.1 Definitions and Acronyms


1.1.1 Definitions
"a12e $9$% Definitions .sed in this Document
NA NA

S)*"+AR# D#S,-N D)C./#N" AR,C#N" C)N*,D#N",A0

1.1.2 Acronyms
T78le 1-2% Acrony9s )sed in this ocu9ent
Acrony9 AS !:pl7n7tion Authentication S!stem

1.2 References
www.wi)ipe ia.com

1.; Document )rganisation


Ch7pter 1 ; < > Intro uction Design ,$er$iew Design Consi eration Architectura% Strategies Contents Specifies scope of the ocument# an its organi9ation. E&p%ains the conte&t of the s!stem# an gi$es an o$er$iew of re3uire functiona%it!. Specifies an! constraints an mentions the esign goa%sImetho s. Specifies esign ecisions affecting the o$era%% architecture of the s!stem# an the e&terna% interfaces.

1.6 Approva2s and Authori:ations


"a12e $9'% Approva2s and Authori:ations
esign7tion Appro$e "! Authori9e "! -ro1ect 4anager Software Engineer +79e Rashi Arora Anupama Singh#'itan1a%i Singh#-rashee% Sinha#Ra$i 'arg#Shi)har 'oe%#Swapni% 7ain 7te <0.0<.;01> <0.0<.;01>

1./ Distri1ution
"a12e $9(% Distri1ution
Copy +o. 1. ;. -older<s esign7tion -ro1ect 4anager Team mem"ers &ssue 7te ;0.01.;01> ;0.01.;01>
8

S)*"+AR# D#S,-N D)C./#N" AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

Chapter

&
2. igh 0eve2 Design 2.1 0eve2 8 Design Description

Figure 2.1: Level 0 DFD: Context Diagram In this conte&t iagram# the user is represente authentication s!stem as a process. as an entit! an the

The user sen s the %ogin etai%s Cuser etai%sD to the authentication s!stem an recei$es the fi%e content if the user is authenticate .

AUTHENTICATION SYSTEM(AS)

2.1.1 ,nterface Description


The input to the authentication s!stem is the user etai%s sent "! the user after the connection is esta"%ishe . The output of the authentication s!stem is the fi%e content if the user is authenticate . The user sen s an ac)now%e gment to the authentication s!stem after recei$ing the fi%e content.

2.2 0eve2 $ Design Description

Figure 2.2: Level 1 DFD: Context Diagram

$8

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

2.2.1 /odu2e name% Authentication System(0eve298)


The Authentication s!stem process in the %e$e%.0 D2D un ergoes ecomposition into man! su".processes each with a uni3ue functiona%it! in the %e$e%.1 D2D.

2.2.1.1

Decomposition Description

Authentication s!stem after successfu% connection with the user ta)es the user etai%s an chec)s whether the user is authenticate to $iew the content of the fi%e or not.5ase on the authentication resu%t it sen s the fi%e content to the user an terminates the connection after recei$ing ac)now%e gment from the user. @ence we ecompose the Authentication s!stem into fo%%owing processes that consists of the these functions. Connection Esta"%ishment Input Authentication Termination

&.&.$.$.$ /odu2e Description


"odule 1 % Connection !st78lish9ent This process waits for the user an esta"%ishes the connection "etween authentication s!stem an user using TC- protoco%. 7t7 escription &nput % Connection Re=uest % The input to this process is a connection re3uest from the user. *utput % The output is the status of the operation i.e. the authentication s!stem an user can communicate with each other.

"odule 2 % &nput This process gi$es user an option to %ogin CE&isting *serD an register CNew userD. 5ase on the choice it ta)es the user etai%s C*sername an passwor D an sen s the etai%s to the authentication process.

AUTHENTICATION SYSTEM(AS)

7t7 escription &nput %

)ser det7ils % *ser name an -asswor *utput % It sen s the user etai%s to the authentication process.

"odule 1 % Authentic7tion This process ta)es the user etai%s an matches the user etai%s in the ata"ase. 5ase on the resu%t the fi%e is sent to the user an recei$es the ac)now%e gment from the user. 7t7 escription &nput % )ser et7ils% *sername an passwor .

2.2.1.2

Dependency Description
The Depen enc! Description is represente "! Structure Charts# which are use in esign to show how software is ecompose into mo u%es. Deri$e the Structure Charts from D2D of this %e$e%. This wi%% capture the epen enc! information.

$&

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

2.1 0eve2 & Design Description


2.1.1 /odu2e name% ,nput(0eve29$)

Figure 2.3.1: Level 2 DFD: Context Diagram The Input process in the %e$e%.1 D2D un ergoes ecomposition into man! su". processes each with a uni3ue functiona%it! in the %e$e%.; D2D.

2.1.1.1

Decomposition Description

Input process gi$es two option to the userCi.e. New user or E&isting userD .E&isting user wi%% enter username an passwor .New user wi%% ha$e to register "! gi$ing uni3ue username an passwor .*ser etai%s are then sent to the authentication process. @ence we ecompose the input into fo%%owing processes that consists of the these functions. (ogin Register

&.'.$.$.$ /odu2e Description


"odule 1 %'ogin

AUTHENTICATION SYSTEM(AS)

This process accepts the user etai%sCusername an passwor D from the e&isting user an sen s the same to the authentication process. 7t7 escription &nput % )ser det7ils% The input to this process is user etai%s Cusername an passwor D of e&isting user. *utput % The output of this process is user etai%s Cusername an passwor D of e&isting user. "odule 2 % Register This process a%%ows a new user to register with uni3ue username an passwor an sen s these etai%s to the authentication process for $a%i it!. 7t7 escription &nput % )ser det7ils% *ser name an -asswor of new user. *utput % It sen s the user etai%s to the authentication process.

&.'.$.& Dependency Description


The Depen enc! Description is represente "! Structure Charts# which are use in esign to show how software is ecompose into mo u%es. Deri$e the Structure Charts from D2D of this %e$e%. This wi%% capture the epen enc! information.

$(

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

2.1.2 /odu2e name% Authentication (0eve29&)

Figure 2.3.2: Level 2 DFD: Context Diagram The Authentication process in the %e$e%.1 D2D un ergoes ecomposition into man! su".processes each with a uni3ue functiona%it! in the %e$e%.; D2D.

2.1.2.1

Decomposition Description
The authentication process accepts username an passwor . It chec)s the a$ai%a"i%it! of the username an sen s the encr!pte passwor to the ata"ase. 2or correct user etai%s fi%e is sent to the user.

AUTHENTICATION SYSTEM(AS)

@ence we ecompose the Authentication process into fo%%owing processes that consists of the these functions. Chec) Encr!ption Sen fi%e

&.'.&.$.$ /odu2e Description


"odule 1 %Chec> This process chec)s the a$ai%a"i%it! of username of the user in the ata"se an sen s ac)now%e gement to the user an encr!ption process. 7t7 escription &nput% )sern79e The input to this process is the username. *utput% )sern79e% *sername of the user. AC#1% It as)s the user to re.enter username. AC#2% It as)s the encr!ption process to match the passwor . "odule 2 % !ncryption This process accepts the passwor #encr!pts it an store it in ata"aseCfor New userDan matches passwor Cfor E&isting *serD.Sen s the ac)now%e gment to sen fi%e process. 7t7 escription &nput% P7ss?ord% passwor of the user AC#2% As)s encr!ption process to match the passwor . *utput % P7ss?ord% Encr!pte passwor is sent to the ata"ase. AC#2% Ac)now%e gment is sent to the sen fi%e process. "odule 1 % $end @ile This process accepts ac)now%e gment of correct username an passwor .Sen s the fi%e to the user. 7t7 escription

$4

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

&nput % AC#2% Ac)now%e gment of correct username an passwor .

*utput $t7tus% 4ile: 2i%e content is sent.

2.1.2.2

Dependency Description
The Depen enc! Description is represente "! Structure Charts# which are use in esign to show how software is ecompose into mo u%es. Deri$e the Structure Charts from D2D of this %e$e%. This wi%% capture the epen enc! information.

2.2 S"R.C".R# D,A-RA/


2.2.1 Structure name% .S#R

4igure 2.2.1 % $tructure

i7gr79AuserB

AUTHENTICATION SYSTEM(AS)

2.2.2 Structure name% S#R;#R

4igure 2.2.2 % $tructure i7gr79AserverB

$6

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

2.2.1 Structure name% thread<fun

4igure 2.2.1 % $tructure i7gr79Athre7d_@unB

Chapter

'
1.A2ternate Design 1.1 A2ternate Designs
2or) can "e use to create separate processes in or er to han %e each c%inet instea of using threa .

AUTHENTICATION SYSTEM(AS)

Instea of creating a new threa for each c%ient threa poo% can "e use .

1.2 Design #va2uation Report


In comparison to threa s# for)ing is much safer an more secure as each for)e process runs in its own $irtua% a ress space. ,ther process wi%% not "e affecte at a%% if an! process crashes or has "uffer o$er.run. *se of threa poo% gi$es the a $antage negating the threa creation an estruction o$erhea # which ma! resu%t in "etter performance an "etter s!stem sta"i%it!.

1.1 Design 0imitations


In or er to use for)# two in epen ent processes has to "e ma e communica"%e with each other in some wa!. E&tra cost is incurre to achie$e this inter.process communication. Resources# such as memor!# etc.# are re3uire "! threa s. Therefore# too %arge threa poo% si9e wi%% put an e&tra %oa on the machine+s resources.

Chapter

(
2.Detai2ed Design
(.$ Detai2ed Data Design

&8

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

Table 4-1.1:

7t7

esign @or Gener7l "7cros

Gener7l "7cros +79e S*CCESS 2AI(*RE 5*2 4AF C@,ICE 4=-,RT 4AFSIAE escription If a function return successfu%%!# returns S*CCESS If a function not return successfu%%!# returns 2AI(*RE 4a&imum %ength of the "uffer 4a&imum %ength of the hash ta"%e T!pe of user. New or E&isting Stores the ser$er+s port num"er 4a&imum si9e of "uffer of each %ine of fi%e ,7lue 1 0 10;> 100 ;0 <8>? ?0

AUTHENTICATION SYSTEM(AS)

T78le % 2-1.2 Design for Error Handling Macros !RR*R -A+ '&+G "ACR*$ +A"! 4&'!_+*T_*P!+ 4&'!_+*T_C'*$! )+!CP!CT! _!*4 "!"*R._4A&')R! R!A _!RR*R DR&T!_!RR*R R!C!&,!_C'&!+T R!C!&,!_$!R,!R $!+ _C'&!+T $!+ _$!R,!R !$CR&PT&*+ &@ there is error opening 7 @ile &@ there is error closing 7 @ile &@ 7 @ile re7ches end o@ @ile une:pectedly &@ 9e9ory is not 7lloc7ted &@ there is error in re7ding &@ there is error in ?riting &@ there is 7n error in receiving @ro9 client &@ there is error in receiving @ro9 server &@ there is error in sending to client &@ there is erro in sending to server 0 1 2 1 2 ; 6 / 5 0 ,A')!

"a12e (9$.' Design for "racing /acros

&&

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

TRAC&+G "ACR*$ +A"! N,ETRACE 5RIE2ETRACE DETAI(EDETRACE . CRITICA(EERR,R 4A7,REERR,R 4IN,REERR,R !$CR&PT&*+ If we want no tracing If we want tracing in a "rief manner If we want tracing in a etai%e manner If error is critica% If error is ma1or If error is minor ,A')! 1 ; < 1 ; <

"a12e (9$.( % Design for -2o1a2 ;aria12es

G'*3A' ,AR&A3'!$ +A"! int gEerrorE%e$e% int gEtraceE%e$e% *ser JhashKL -threa Emute&Et mute Int s Int numEusers !$CR&PT&*+ Error han %ing %e$e% Tracing %e$e% '%o"a% hash ta"%e for storing ata"ase 2or putting a mute& %oc) on the $aria"%e mai% Soc)et escriptor of ser$er Count of num"er of authenticate users in the ata"ase

2.1.1 Data Structure%Structure for user detai2s


Struct user M

AUTHENTICATION SYSTEM(AS)

Char JusernameNIJ@o% s username of a userJI Char Jpasswor NIJ@o% s passwor of a userJI Char JuserEt!peNIJ@o% s weteher user is new or e&istingJI Struct user Jne&tN ON

2.1 Detai2ed /odu2e design


"* )'! 1% G!T
-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s Dec%aration of the hash ta"%e NA The hash ta"%e is %oa e with the contents of the ata "ase. Returns S*CCESS or 2AI(*RE Ser$er main function. num"erofusersCD# hashCD#to)eniseCD -SE*D, C,DE 2*NCTI,N : $oi get ata"aseCD 5E'IN : 1.0 ;.0 <.0 fp P fopenC/ ata"ase0#0r0D numEusers P num"erofusersCD forCiP0 increments "! 1 ti%% numEusersD <.1 <.; <.< <.> <.? <.8 <.: <.6 <.B <.10 <.11 <.1;
&(

ATA3A$!

int getdatabase()
(oa s the contents of the ata"ase fi%e into the hash ta"%e

memsetC"uffer#0#4AFSIAED fgetsC"uffer#4AFSIAE#fpD to)eniseC"uffer#wor D o"1 P Cuser JDma%%ocCsi9eofCuserDDN %en EnamePstr%enCwor K0LD o"1.Qusername P Cchar JDma%%ocC%enEnameJsi9eofCcharDD strncp!Co"1.Qusername#wor K0L#%enEnameD %en EpassPstr%enCwor K1LD o"1.Qpasswor P Cchar JDma%%ocC%enEpassJsi9eofCcharDD strncp!Co"1.Qpasswor #wor K1L#%enEpassD o"1.Qne&tPN*(( )Phashta"%eCo"1.QusernameD
ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

<.1< <.1> <.1? <.18 <.1:

ifChashta"%eK)L is N*((D hashta"%eK)LPo"1 e%se o"1.Qne&tPhashta"%eK)L hashta"%eK)LPo"1 END

"* )'! 2% +)"3!R *4 )$!R$


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s

int numberofusers(FILE *)
2in s the num"er of %ines in the fi%e which correspon s to the num"er of users in the ata"ase NA 2i%e pointer Num"er of %ines is ca%cu%ate Num"er of users get ata"aseCD NA

-SE*D, C,DE 2*NCTI,N : int num"erofusersC2I(E JfpD 5E'IN : 1.0 ;.0 ;.1 ;.; ;.< ;.> ;.? <.0 user P 0 whi%eCen of fi%e not reache D memsetC"uffer#0#4AFSIAED fgetsC"uffer#4AFSIAE#fpD ifCen of fi%eD "rea) user P user R1 return user END

"* )'! 1% T*#!+&$!


-rotot!pe

void tokenise(char *buffer,char *word[])

AUTHENTICATION SYSTEM(AS)

-urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s

To)enise the string "uffer an store it into wor NA ,rigina% string to "e to)eni9e "uffer an empt! to)eni9e string wor To)enise the string "uffer an store it into wor NA get ata"aseCD#threa EfunCD NA -SE*D, C,DE 2*NCTI,N : to)eniseCchar J"uffer#char Jwor KLD 5E'IN 1.0 ;.0 <.0 <.1 <.; >.0 iP0 wor KiLPstrto)C"uffer#0 Sn/D whi%eCwor KiL is not N*((D iRR wor KiLPstrto)CN*((#0 Sn/D END

"* )'! 2% -A$-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s

Int hash(char *string)


'enerates the in e& of the hash ta"%e using the sum of the ASCII $a%ues of string an oing its mo u%us "! 100 @ash ta"%e *sername to "e use to generate the hash ta"%e in e& In e& of the hash ta"%e ca%cu%ate summing the ASCII $a%ues of the string an mo u%us In e& of the hash ta"%e get ata"aseCD#searchEusernameCD#insertEhashta"%eCD NA oing its

-SE*D, C,DE 2*NCTI,N : int hashCchar JstringD


&4 ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

5E'IN 1.0: ;.0 <.0 <.1 >.0 ?.0 8.0 sum P 0 %en P str%enCstringD forCiP0 increments "! 1 ti%% %enD sum RP stringKiL in e&PsumT100 return in e& END

"* )'! ;% T-R!A 4)+CT&*+


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s NA Acti$e Soc)et escriptor as input C%oses the ser$er soc)et an terminates the ser$er NA 4ain Threa in the ser$er recei$eEuserEcre entia%sCD#searchEusernameCD#sen Eac)now%e gementEtoEuserCD# encr!ptionCD#insertEhashta"%eCD#authenticationEchec)CD#sen EtoEc%ientCD#to)eniseCD -SE*D, C,DE 2*NCTI,N : $oi J threa EfunC$oi Js D 1.0 ;.0 <.0 >.0 ?.0 8.0 :.0 :.1 :.; :.< :.> :.>.1 :.>.; :.>.< :.>.> 5E'IN connf PCintDs f%agP0 chanceP0 pthrea E etachCpthrea Ese%fCDD f P openC/fi%e0#,ERD,N(=D whi%eC< Q chanceD memsetC"uf#0#4AFD recei$eEuserEcre entia%Cconnf #"ufferD to)eniseC"uffer#to)enD ifCstrcmpC/NewEuser0#to)enK0LD is 0D pthrea Emute&E%oc)CUmuteD retPsearchEusernameCD sen Eac)now%e gementEtoEuserCret#connf D ifCretPPS*CCESSD

void* thread_fun(void *sd)


Threa 2unction ca%%s the re3uire functions to recei$e user etai%s from the c%ient

:.>.>.1 memsetC"uf#0#4AFD

AUTHENTICATION SYSTEM(AS)

:.>.>.; recei$eEuserEcre entia%Cconnf #"ufferD :.>.>.< to)eniseC"uffer#to)enD :.>.>.> insertEhashta"%eCto)enK1L#to)enK;LD :.>.>.? pthrea Emute&E%oc)CUmuteD :.>.>.8 f%agP1 :.>.>.: "rea) :.>.? e%se :.>.?.1 f%agP0 :.>.?.; chanceRR :.>.?.< pthrea Emute&Eun%oc)CUmuteD :.>.?.> continue :.? :.?.1 :.?.; :.?.< e%se retPauthenticationEchec)Cto)enK1L#to)enK;LD sen Eac)now%e gementEtoEuserCret#connf D ifCretPPS*CCESSD

:.?.<.1 f%agP; :.?.<.; sen EtoEc%ientCf #connf D :.?.<.< "rea) :.?.> e%se :.?.>.1 f%agP0 :.?.>.; iP0 :.?.>.< chanceRR 6.0 6.1 B.0 10.0 11.0 ifCf%agPP1D sen EtoEc%ientCf #connf D c%oseCconnf D pthrea Ee&itCN*((D END

"* )'! 6% &+P)T '*G&+ CR! !+T&A'$


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Soc)et connection esta"%ishe Acti$e soc)et escriptor Chec)s user t!pe an then ta)es the respecti$e %ogin etai%s Returns S*CCESS or 2AI(*RE C%ient 4ain function

Int in ut_!ogin_credentia!(int sd)


Input the user etai%s: user t!pe#user name an passwor

&6

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

Ca%%s

Sen E%oginEcre entia%CD#rea Esoc)etCD -SE*D, C,DE 2*NCTI,N : int inputE%oginEcre entia%sCint s D 1.0 ;.0 ;.1 ;.; ;.< ;.<.1 ;.<.; ;.<.< ;.<.> ;.<.? ;.<.8 ;.<.: ;.<.6 ;.<.B 5E'IN whi%eC1D printfCinput 1 for new user an ; for e&isitingD scanfC/T 0#UchoiceD switchCchoiceD case 1 whi%eC<QchanceD strcp!Ct!peEuser#/NewEuser0D input username memsetC"uf#0#4AFD strcatC"uf#t!peEuserD strcatC"uf#0 /D strcatC"uf#usernameD strcatC"uf#0V0D

;.<.10 sen E%oginEcre entia%C"uf#s D ;.<.11 retPrea Esoc)etCs D ;.<.1; ifCretPPS*CCESSD ;.<.1< "rea) ;.<.1> e%se ;.<.1? chanceRR ;.<.18 ifCchanceP<D ;.<.1: return 2AI(*RE ;.<.16 memsetC"uf#0#4AFD ;.<.1B input passwor ;.<.;0 strcatC"uf#t!peEuserD ;.<.;1 strcatC"uf#0 /D ;.<.;; strcatC"uf#usernameD ;.<.;< strcatC"uf#0 /D ;.<.;> strcatC"uf#passwor D ;.<.;? strcatC"uf#0V0D ;.<.;8 sen E%oginEcre entia%C"uf#s D ;.> ;.>.1 ;.>.; ;.>.< ;.>.> ;.>.? case ; whi%eC<QchanceD strcp!Ct!peEuser#/E&isitingEuser0D input username memsetC"uf#0#4AFD strcatC"uf#t!peEuserD

AUTHENTICATION SYSTEM(AS)

;.>.8 ;.>.: ;.>.6 ;.>.B

strcatC"uf#0 /D strcatC"uf#usernameD input passwor strcatC"uf#passwor D

;.>.10 strcatC"uf#0V0D ;.>.11 sen EuserEcre entia%C"uf#s D ;.>.1; retPrea Esoc)etCs D ;.>.1< ifCretPP2AI(*RED ;.>.1> f%agP0 ;.>.1? chanceRR ;.>.18 e%se ;.>.1: f%agP1 ;.>.16 "rea) ;.? ;.?.1 <.0 <.1 >.0 >.1 >.; efau%t printfCwrong choiceD ifCf%agWP1D return 2AI(*RE e%se return S*CCESS END

"* )'! /% $!+


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s

'*G&+ CR! !+T&A'$

int send_!ogin_credentia!(char *buf, int sd)


Sen the user etai%s to authentication s!stem: user t!pe#user name an passwor Soc)et connection esta"%ishe # Inputte user t!pe# user name an passwor Acti$e soc)et escriptor# *ser etai%s Sen s user etai%s to authentication s!stem Returns S*CCESS or 2AI(*RE inputE%oginEcre entia%CD NA -SE*D, C,DE 2*NCTI,N : int sen E%oginEcre entia%Cchar J"uf# int s D 1.0 5E'IN ;.0 int "!teswritten P 0# written P 0# %en P 0 <.0 %en P str%enC"ufD

'8

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

>.0 whi%eC"!teswritten X %enD >.1 written P writeCs # "ufR"!teswritten# %en."!teswrittenD >.; ifC0 Q writtenD >.;.1 ?.0 ff%ushCst outD 8.0 return S*CCESS :.0 END return 2AI(*RE >.< "!teswritten P "!teswritten R written

"* )'! 5% R!C!&,! )$!R CR! !+T&A'


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s Soc)et connection esta"%ishe Connection escriptor# "uffer Stores the user etai%s in the "uffer for further e&ecution Returns S*CCESS or 2AI(*RE threa EfunCD NA -SE*D, C,DE 2*NCTI,N : int recei$eEuserEcre entia%Cint connf # char J"ufD 1.0 5E'IN ;.0 Int n P0# pointer P 0 <.0 whi%eCCn P rea Cconnf # "ufRpointer# 4AFDD Q 0D <.1 ifC0 Q nD <.1.1 return 2AI(*RE <.; pointer P pointer R n <.< ifCYV+ PP "ufKn.1LD <.<.1 <.<.; >.0 return S*CCESS ?.0 END "ufKn.1L P YS0+ "rea)

int receive_user_credentia!(int connfd, char *buf)


Recei$e the user etai%s: user t!pe#user name an passwor

AUTHENTICATION SYSTEM(AS)

"* )'! 0% $!ARC- )$!R+A"!


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s @ash ta"%e %oa e with ata"ase *sername inputte "! the user Chec)s if the username a%rea ! e&ists in the ata"ase or not Returns S*CCESS if username is not e&isting in the ata"ase e%se 2AI(*RE threa EfunCD hashCD -SE*D, C,DE 2*NCTI,N : int searchEusernameCchar JusernameD 5E'IN 1.0 ;.0 <.0 <.1 <.1.1 <.; >.0 ?.0 in e& P hashCusernameD tempPhashta"%eKin e&L whi%eCtemp is not N*((D ifCstrcmpCtemp.Qusername#usernameD is 0D return 2AI(*RE temp P temp.Qne&t return S*CCESS END

Int search_username(char *username)


Chec)s for the a$ai%a"i%it! of the username for the new user

"* )'! 10% $!+


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s
'&

AC#+*D'! G"!+T T* )$!R

void send_acknow!edgment_to_user(int ret, int connfd)


Sen s an ac)now%e gement to the user a"out the username a$ai%a"i%it! for the new user an successfu% %ogin of the e&isting user. *sername a$ai%a"i%it! is chec)e for new users# username an passwor is matche for e&isting users Return $a%ue of search# connection escriptor Ac)now%e gement to the users a"out %oginIregister success or fai%ure NA threa EfunCD NA
ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

-SE*D, C,DE 2*NCTI,N : $oi sen Eac)now%e gmentEtoEuserCint ret# int connf D 1.0 5E'IN ;.0 char "ufK10L <.0 memsetC"uf# 0# 10DN >.0 ifCS*CCESS PP retD >.1 strcp!C"uf# /S*CCESSV0DN >.; writeCconnf # "uf# str%enC"ufDDN ?.0 e%se ?.1 strcp!C"uf# /2AI(*REV0DN ?.; writeCconnf # "uf# str%enC"ufDDN 8.0 END

"* )'! 11% R!A $*C#!T


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s

int read_socket(int sd)


Recei$es message from the authentication s!stem if user %oginIregister was successfu% or not Soc)et connection esta"%ishe Acti$e soc)et escriptor Success or fai%ure of user %oginIregister Returns S*CCESS or 2AI(*RE InputE%oginEcre entia%CD NA -SE*D, C,DE 2*NCTI,N : int rea Esoc)etCint s D 1.0 5E'IN ;.0 int pointer P 0# n P 0 <.0 char "ufK4AFL >.0 whi%eCCn P rea Cs # "ufRpointer# 4AFDD Q 0D >.1 pointer P pointer R n >.; ifCYV+ PP "ufKn.1LD >.;.1 >.;.; "ufKn.1L P YS0+ "rea)

?.0 ifC0 PP strcmpC"uf# /S*CCESS0DD ?.1 return S*CCESS

AUTHENTICATION SYSTEM(AS)

8.0 e%se ifC0 PP strcmpC"uf# /2AI(*RE0DD 8.1 return 2AI(*RE :.0 return S*CCESS 6.0 END

"* )'! 12 % !+CR.PT&*+


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s *sername a$ai%a"i%it! chec)e for new user -asswor inputte "! the user The passwor is encr!pte NA threa EfunCD NA -SE*D, C,DE 2*NCTI,N : $oi encr!ptionCchar Jpasswor D 1.0 ;.0 <.0 >.0 >.0 5E'IN %en P str%enCpasswor D forCti%% %enD forCti%% %enD END

void encr" tion(char* assword)


Encr!pts the passwor

<.1.1 temp P Zpasswor >.1.1 passwor P temp R <

"* )'! 11 % &+$!RT &+ -A$-TA3'!


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return
'(

void insert_hashtab!e(char *username,char* assword)


Inserts New user etai%s into the hash ta"%e *sername a$ai%a"i%it! chec)e *sername an -asswor inputte "! the user Inserts the *sername an -asswor of the new user into the hash ta"%e NA
ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

Va%ueCsD Ca%%e 5! Ca%%s threa EfunCD hashCD#writeEtoEfi%eCD -SE*D, C,DE 2*NCTI,N : $oi insertEhashta"%eCchar Jusername#char Jpasswor D ?.0 8.0 :.0 6.0 B.0 5E'IN user Jtemp %en P str%enCusernameD %enEpassPstr%enCpasswor D temp P Cuser JDma%%ocCsi9eofCuserDD

10.0 temp.QusernamePCcharJDma%%ocCC%enR1DJsi9eofCcharDD 11.0 strncp!Ctemp.Qusername#username#%enD 1;.0 temp.Qpasswor PCcharJDma%%ocCC%enEpassR1DJsi9eofCcharDD 1<.0 strncp!Ctemp.Qpasswor #passwor #%enEpassD 1>.0 temp.Qne&t P N*(( 1?.0 in e& P hashCusernameD 1; 1;.1 1;.; 1< 1<.1 1<.; 1<.< 1> 1? ifChashta"%eKin e&L is N*((D hashta"%eKin e&LPtemp numEusers RP1 e%se o"1.Qne&tPhashta"%eKin e&L hashta"%eKin e&LPtemp numEuser RP 1 writeEtoEfi%eCusername#passwor D END

"* )'! 12%DR&T! T* 4&'!


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s @ashta"%e %oa e with ata"ase *sername an passwor Inserts the etai%s in the ata"ase S*CCESS on successfu% write in the fi%e an 2AI(*RE of fi%e is not opene proper%! InsertEinEhasta"%eCD NA -SE*D, C,DE 2*NCTI,N :$oi writeEtoEfi%eC$oi D

Int write_to_fi!e(char *username,char * assword)


*p ates the ata"se with the etai%s of new userC i.e New username an passwor D

AUTHENTICATION SYSTEM(AS)

5E'IN 1.0 ;.0 ;.1 <.0 <.1.1 <.1.; >.0 fp P fopenCopen fi%e in appen mo eD ifCfp is N*((D return 2AI(*RE e%se fprintfCusernameD fprintfCpasswor D return S*CCESS

"* )'! 1;% A)T-!+T&CAT&*+ C-!C#


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s

Int authentication_check(char *username,char* assword)


Chec)s for the e&istence of the e&isting user searching the username an chec)s the passwor for it @ashta"%e %oa e with ata"ase *sername an -asswor inputte "! the user Searches for the username in the hash ta"%e an then chec)s the passwor Returns S*CCESS if passwor matches e%se returns 2AI(*RE threa EfunCD hashCD -SE*D, C,DE 2*NCTI,N :int authenticationEchec)Cchar Jusername#char Jpasswor D 5E'IN ?.0 8.0 :.0 :.1 :.1.1 :.1.; :.1.< :.; 6.0 B.0 in e& P hashCusernameD user Jptr P hashta"%eKin e&L whi%eCptr is not N*((D ifCstrcmpCptr.Qusername#usernameD is 0D ifCstrcmpCptr.Qpasswor #passwor D is 0D f%agP1 return S*CCESS ptr P ptr.Qne&t ifCf%ag is 0D return 2AI(*RE

10.0 END

'4

ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

"* )'! 16% $!+


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s *ser authentication 2i%e escriptor# acti$e soc)et escriptor 2i%e is sent NA threa EfunCD NA -SE*D, C,DE

T* C'&!+T

void send_to_c!ient(int fd, int sd)


Sen fi%e to authenticate user

2*NCTI,N : $oi sen EtoEc%ientCint f # int s D 1.0 5E'IN ;.0 struct stat s <.0 int si9e#n P 0#"!teswritten P 0#written P 0 >.0 fstatCf # UsD ?.0 si9e P s.stEsi9e 8.0 char J"uf :.0 "uf P Cchar JDma%%ocCCsi9eR1DJsi9eofCcharDD 6.0 ifCN*(( PP "ufD 6.1 printfC/Sn memor! not a$ai%a"%e in heap0D 6.; c%oseCs D 6.< pthrea Ee&itCN*((D B.0 memsetC"uf# 0# Csi9eR1DD 10.0 n P rea Cf # "uf# si9eR1D 11.0 "ufKn.1L P YV+ 1;.0 whi%eC"!teswritten X nD 1;.1 written P writeCs # "ufR"!teswritten# n."!teswrittenD 1;.; ifC0 Q writtenD 1;.;.1 printfC/SnError in writing to soc)et0D 1;.;.; c%oseCs D 1;.;.< pthrea Ee&itCN*((D 1;.< "!teswritten P "!teswritten R written 1;.0 END

AUTHENTICATION SYSTEM(AS)

"* )'! 1/% R!C!&,! 4R*" $!R,!R


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s *ser shou% "e %ogge in Acti$e soc)et escriptor# "uffer 2i%e recei$e from the authentication s!stem Returns S*CCESS or 2AI(*RE C%ient 4ain function NA -SE*D, C,DE 2*NCTI,N : int recei$eEfromEser$erCint s # char J"ufferD 1.0 5E'IN ;.0 int f P 0# n P0# pointer P 0#ret P 0 <.0 char "ufK4AFL >.0 memsetC"uf# 0# 4AFD ?.0 whi%eCCn P rea Cs # "ufRpointer# 4AFDD Q 0D ?.1 pointer P pointer R n ?.; ifCYV+ PP "ufKn.1LD ?.;.1 ?.;.; ?.;.< ?.;.> ?.< pointer P 0 ?.> return S*CCESS ?.? END "ufKn.1L P YS0+ strncp!C"uffer# "uf# str%enC"ufDR1D printfC/SnTs0# "ufferD "rea)

int receiver_from_server(int sd, char *buffer)


Recei$es fi%e from the ser$er

"* )'! 15% $&G+A' -A+ '!R


-rotot!pe -urposeI Description -re.
'6

void signa!_hand!er(int signo)


Terminates the ser$er on recei$ing Ctr%RC NA
ARICENT: AR,C#N" C)N*,D#N",A0

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s Recei$es signa% SI'INT C%oses the ser$er soc)et an terminates the ser$er NA Ser$er 4ain function freeEuserCD -SE*D, C,DE 2*NCTI,N : $oi signa%Ehan %erCint signoD 1.0 ;.0 ;.1 ;.; ;.< <.0 5E'IN ifCsignoPPSI'INTD c%oseCs D freeEuserCD pthrea Ee&itCN*((D END

"* )'! 10 % 4R!! )$!R


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s NA NA 2rees the user structure NA Signa%Ehan %erCD NA -SE*D, C,DE 2*NCTI,N : $oi freeEuserCD 5E'IN 1.0 1.1 1.; 1.;.1 1.;.; 1.;.< 1.;.> forCiP0 increments "!1 ti%% numEusersD temp P hashta"%eKiL whi%eCtemp is not N*((D freeCtemp.QusernameD temp.Qusername P N*(( freeCtemp.Qpasswor D temp.Qpasswor PN*((

void free_user()
2rees the user mermor! a%%ocate

AUTHENTICATION SYSTEM(AS)

1.;.? 1.;.8 1.;.: 1.;.6 ;.0

temp1Ptemp tempPtemp1.Qne&t freeCtemp1D temp1PN*(( END

"* )'! 20% $&G+A' -A+ '!R


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! Ca%%s NA Recei$es signa% SI'INT C%oses the soc)et an terminates the c%ient NA *ser main function NA -SE*D, C,DE 2*NCTI,N : $oi signa%Ehan %erCint signoD 1.0 ;.0 ;.1 ;.; <.0 5E'IN ifCsignoPPSI'INTD c%oseCs D e&itC1D END

#oid signa!_hand!er(int signo)


Terminates the c%ient on recei$ing Ctr%RC

"* )'! 21% !RR*R -A+ '!R


-rotot!pe -urposeI Description -re. re3uisites InputCsD ,utputCsD Return Va%ueCsD Ca%%e 5! NA Recei$es ifferent error co es an error %e$e% for ifferent error messeges Disp%a! ifferent error messeges NA 4ainCD#inputE%oginEcre entia%CD#rea Esoc)etCD#sen E%oginEcre entia%CD#recei$eEfromEser $erCD#threa EfunCD#recei$eEuserEcre entia%CD#sen EtoEc%ientCD#sen Eac)now%e gmentEto
ARICENT: AR,C#N" C)N*,D#N",A0

#oid error_hand!er(int !eve!,int ercode)


Error han %er function which isp%a!s appropriate error messeges

(8

ERROR! NO TEXT OF SPECIFIED STYLE IN DOCUMENT.

EuserCD#get ata"aseCD#insertEhashEta"%eCD#authenticationEchec)CD#writeEtoEfi%eCD Ca%%s NA -SE*D, C,DE 2*NCTI,N : $oi errorEhan %erCint %e$e%#int erco eD 1.0 ;.0 ;.1 ;.1.1 <.0 5E'IN Char JstrKL PM ifferent error messegesO IfCgEerrorE%e$e% QP %e$e%D printfCstrKerco eLD END

Potrebbero piacerti anche