Esempio n. 1
0
        protected void setOTP(ref Client client, ref SqlCommand sqlCmd, int account_id)
        {
            // Formulate an OTP
            string otpHash = OTP.GenerateRandomPassword(26);

            if (debug)
            {
                Console.WriteLine("\t-Generated OTP: {0}", otpHash);
            }

            // Check if OTP account_id already exists
            sqlCmd.CommandText = "SELECT COUNT(account_id) FROM dbo.OTP WHERE account_id = @account_id";

            object result = Database.ExecuteStatement(sqlCmd, 1);

            if ((int)result == 1) // OTP account_id exists, update OTP
            {
                if (debug)
                {
                    Console.Write("\t-Updating OTP...");
                }

                sqlCmd.CommandText = "UPDATE dbo.OTP SET otp = @OTP, expiration = @expiration WHERE account_id = @account_id";
                sqlCmd.Parameters.Add("@OTP", SqlDbType.NVarChar).Value        = otpHash;
                sqlCmd.Parameters.Add("@expiration", SqlDbType.DateTime).Value = DateTime.Now.AddMinutes(5);

                result = Database.ExecuteStatement(sqlCmd, 0);

                if (debug)
                {
                    Console.WriteLine(((int)result == 1) ? "[SUCCESS]" : "[FAIL]");
                }
            }
            else // OTP account_id doesn't exist, write new OTP
            {
                if (debug)
                {
                    Console.Write("\t-Inserting OTP...");
                }

                sqlCmd.CommandText = "INSERT INTO dbo.OTP (account_id, otp, expiration) VALUES (@account_id, @OTP, @expiration)";
                sqlCmd.Parameters.Clear();
                sqlCmd.Parameters.Add("@account_id", SqlDbType.Int).Value      = account_id;
                sqlCmd.Parameters.Add("@OTP", SqlDbType.NVarChar).Value        = otpHash;
                sqlCmd.Parameters.Add("@expiration", SqlDbType.DateTime).Value = DateTime.Now.AddMinutes(5);

                result = Database.ExecuteStatement(sqlCmd, 0);

                if (debug)
                {
                    Console.WriteLine(((int)result == 1) ? "[SUCCESS]" : "[FAIL]");
                }
            }

            ClientPackets.Instance.SC_SendOTP(client, otpHash);
        }
Esempio n. 2
0
        internal string compressFile(string filePath)
        {
            string name    = OTP.GenerateRandomPassword(10);
            string zipPath = Path.Combine(Program.tmpPath, string.Concat(name, ".zip"));

            Zipper z = new Zipper();

            z.ItemList.Add(filePath);
            z.ZipFile = zipPath;
            z.Zip();
            z = null;

            return(name);
        }