Пример #1
0
        private static Shfrytezuesi getShfrytezuesi(string username)
        {
            objXml.Load("shfrytezuesi" + ".xml");
            XmlNodeList shfrytezuesiElements = objXml.GetElementsByTagName("shfrytezuesi");

            Shfrytezuesi shfrytezuesi = new Shfrytezuesi();

            for (int i = 0; i < shfrytezuesiElements.Count; i++)
            {
                string usernameXml     = shfrytezuesiElements[i].SelectSingleNode("username").InnerText;
                string personiXml      = shfrytezuesiElements[i].SelectSingleNode("personi").InnerText;
                string llojifaturesXml = shfrytezuesiElements[i].SelectSingleNode("llojifatures").InnerText;
                string vitiXml         = shfrytezuesiElements[i].SelectSingleNode("viti").InnerText;
                double vleraeuroXml    = Double.Parse(shfrytezuesiElements[i].SelectSingleNode("vleraeuro").InnerText);
                string muajiXml        = shfrytezuesiElements[i].SelectSingleNode("muaji").InnerText;

                if (username.Equals(usernameXml))
                {
                    shfrytezuesi = new Shfrytezuesi(personiXml, llojifaturesXml, vitiXml, vleraeuroXml, muajiXml, usernameXml);
                }
            }



            return(shfrytezuesi);
        }
Пример #2
0
        private static void handleConnection(ref Socket connSocket)
        {
            IPEndPoint clientIp = (IPEndPoint)connSocket.RemoteEndPoint;

            Console.WriteLine("Serveri u lidh me hostin {0} ne portin {1}", clientIp.Address, clientIp.Port);



            connSocket.Receive(desKey);
            connSocket.Receive(desIV);
            if (objDes == null)
            {
                createDes();
            }



            while (true)
            {
                byte[] byteFromClient = new byte[1024];
                int    length         = connSocket.Receive(byteFromClient);
                string strFromClient  = Encoding.UTF8.GetString(byteFromClient, 0, length);


                Console.WriteLine("Client: (Ciphertext) {0} \n", strFromClient);
                string fromClientDecrypted = dekriptoDes(strFromClient);
                Console.WriteLine("Client: (Plaintext) {0} \n", fromClientDecrypted);

                string[] tokens = fromClientDecrypted.Split(' ');
                Console.WriteLine(tokens.Length);

                string strFromServer = "";
                if (tokens.Length == 2)
                {
                    string username = tokens[0].Trim();
                    string password = tokens[1].Trim();

                    if (isValidLogin(username, password))
                    {
                        strFromServer = "You are logged in!";
                        DataSet      dsShfrytezuesi = new DataSet();
                        Shfrytezuesi shfrytezuesi   = getShfrytezuesi(username);
                        string       jsonWebToken   = generateJWT(shfrytezuesi.personi, shfrytezuesi.llojifatures, shfrytezuesi.viti, shfrytezuesi.vleraeuro, shfrytezuesi.muaji, shfrytezuesi.username);
                    }
                    else
                    {
                        strFromServer = "false";
                    }
                }
                else
                {
                    string personi      = tokens[0];
                    string llojifatures = tokens[1];
                    string muaji        = tokens[2];
                    string viti         = tokens[3];
                    double vleraeuro    = Double.Parse(tokens[4]);
                    string username     = tokens[5].Trim();
                    string password     = tokens[6].Trim();
                    //string saltedHash = tokens[7];

                    try
                    {
                        addShfrytezuesi(personi, llojifatures, viti, vleraeuro, muaji, username, password);
                        strFromServer = "true";
                        //Console.WriteLine(strFromServer);
                    }
                    catch (Exception ex)
                    {
                        strFromServer = "User has not been added!! \n" + ex.Message;
                        //Console.WriteLine(strFromServer);
                    }
                }


                //
                // Serveri kthen diqka ...
                //


                Console.WriteLine("Server: (Plaintext) {0} \n", strFromServer);
                string strFromServerEncrypted = enkriptoDes(strFromServer);
                connSocket.Send(Encoding.UTF8.GetBytes(strFromServerEncrypted));
                Console.WriteLine("Server: (Ciphertext) {0} \n", strFromServerEncrypted);
            }
        }