Ejemplo n.º 1
0
        public bool LogIn(string Login, string Password)
        {
            bool                Result            = false;
            SQLiteConnection    db                = new SQLiteConnection(DataBasePath);
            List <UserClass>    DataUserImport    = new List <UserClass>();
            List <StorageClass> DataStorageImport = new List <StorageClass>();

            DataUserImport    = db.Query <UserClass>("SELECT * FROM UserTable WHERE ColumnUsername='******'");
            DataStorageImport = db.Query <StorageClass>("SELECT * FROM StorageKeys WHERE UserId='" + DataUserImport[0].Id + "'");

            if (DataUserImport.Count > 0)
            {
                if (DataUserImport[0].PassWord != HashFunc.GetHash(Password))
                {
                    MessageBox.Show("Password incorrect!");
                    LoginState.OnNext(false);
                    Result = false;
                }
                else
                {
                    UserName.OnNext(DataUserImport[0].UserName);
                    LoginState.OnNext(true);
                    DropBoxToken.OnNext(DataStorageImport[0].DropBox);
                    Result = true;
                }
            }
            else
            {
                MessageBox.Show(Login + " not found!");
                LoginState.OnNext(false);
                Result = false;
            }

            return(Result);
        }
Ejemplo n.º 2
0
        public NameTableReader(SpanStream r)
        {
            UInt32 magic = r.ReadUInt32();

            if (magic != MAGIC)
            {
                throw new InvalidDataException($"Invalid verHdr magic 0x{magic:X}");
            }

            Version = r.ReadEnum <NameTableVersion>();
            switch (Version)
            {
            case NameTableVersion.Hash:
                hasher = HasherV1.HashData;
                break;

            case NameTableVersion.HashV2:
                hasher = HasherV2.HashData;
                break;
            }

            byte[] buf = Deserializers.ReadBuffer(r);
            rdr = new SpanStream(buf);

            Indices          = Deserializers.ReadArray <UInt32>(r);
            NumberOfElements = r.ReadUInt32();
        }
Ejemplo n.º 3
0
 public BasicFilter(int width, HashFunc hashFunction = HashFunc.SHA256, ushort hashNumber = 3)
 {
     Width        = width;
     HashFunction = hashFunction;
     Filter       = new byte[(uint)Math.Ceiling((double)Width / 8)];
     HashNumber   = (uint)Math.Min(hashNumber, prefix.Length);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// <see cref="BasicFilter"/> constructor exposing expected number and probability parameters.
 /// </summary>
 /// <param name="expectedNoItems">The number of items expected to be inserted into the filter.</param>
 /// <param name="fpProb">Targeted probability of false positives showing up.</param>
 /// <param name="hashFunction"><see cref="HashFunc"/> to use while inserting and checking.</param>
 public BasicFilter(int expectedNoItems, double fpProb, HashFunc hashFunction = HashFunc.SHA256)
 {
     Width        = (int)Math.Ceiling((expectedNoItems * Math.Log(fpProb)) / Math.Log(1 / Math.Pow(2, Math.Log(2))));
     HashFunction = hashFunction;
     Filter       = new byte[(uint)Math.Ceiling((double)Width / 8)];
     HashNumber   = (uint)Math.Round((Width / expectedNoItems) * Math.Log(2));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Метод добавляет значение в коллекцию. Если хэш-таблица заполнена - вернёт -1.
        /// Если возникает коллизия - метод будет производить рехэширование до тех пор, пока не найдёт место.
        /// </summary>
        /// <param name="word">Значение, которое нужно добавить в коллекцию</param>
        /// <returns>Возвращает индекс, под которым хранится слово помещено слово.</returns>
        public int Add(string word)
        {
            if (this.size == this.values.Length)
            {
                return(-1);
            }

            if (this.IsExists(word))
            {
                return(-1);
            }

            int index = HashFunc.CreateHash(word);

            int lvlOfRehash = 1;

            while (values[index] != null)
            {
                index = ReHashFunc.Rehash(index, lvlOfRehash);
                lvlOfRehash++;
            }

            values[index] = new Cell(word, --lvlOfRehash);

            this.size++;
            return(index);
        }
Ejemplo n.º 6
0
 public CachedHash(HashFunc hashFunc,
                   FailureBehavior failureBehavior     = FailureBehavior.AssertFailures,
                   CachabilityTestFunc cachabilityTest = null)
 {
     this._hashCache       = new Dictionary <HashedObjectType, ValueType>();
     this._hashFunc        = hashFunc;
     this._failureBehavior = failureBehavior;
     this._cachabilityTest = cachabilityTest;
 }
Ejemplo n.º 7
0
        public string DoHash(RenderTarget2D input, HashFunc hash_func)
        {
            hash_func(input, HashField, Output: Multigrid[0]);

            vec4 hash = MultigridReduce((tx, rt) => HashReduce.Apply(tx, HashField, rt));

            string s = string.Format("{0}{1}{2}{3}", hash.x, hash.y, hash.z, hash.w);

            return(s.GetHashCode().ToString());
        }
Ejemplo n.º 8
0
        // SaltID is used to apply a salt and hash function to an ID to make sure
        // it is not reversible
        //~ func SaltID(salt, id string, hash HashFunc) string {
        public static string SaltID(string salt, string id, HashFunc hash)
        {
            //~ comb := salt + id
            //~ hashVal := hash([]byte(comb))
            //~ return hex.EncodeToString(hashVal)
            var comb    = salt + id;
            var hashVal = hash(comb.ToUtf8Bytes());

            return(BitConverter.ToString(hashVal).Replace("-", ""));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Ensures instance of SHA256 hash provider.
 /// </summary>
 private void EnsureSha256()
 {
     if (sha256 == null)
     {
         lock (sha256Lock)
         {
             if (sha256 == null)
             {
                 sha256 = CreateSha256();
             }
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Ensures instance of SHA1 hash provider.
 /// </summary>
 private void EnsureSha1()
 {
     if (sha1 == null)
     {
         lock (sha1Lock)
         {
             if (sha1 == null)
             {
                 sha1 = CreateSha1();
             }
         }
     }
 }
Ejemplo n.º 11
0
        public bool IsValueStoredAsRehash(string word)
        {
            if (!IsExists(word))
            {
                return(false);
            }

            int index = HashFunc.CreateHash(word);

            if (values[index].Value == word)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// <see cref="IHashProvider"/> factory.
        /// </summary>
        /// <param name="func">Hash function to use; see <see cref="HashFunc"/>.</param>
        /// <returns></returns>
        private IHashProvider CreateHashAlgorithm(HashFunc func)
        {
            switch (func)
            {
            case HashFunc.SHA256:
                return(SHA256Provider.Create());

            case HashFunc.SHA512:
                return(SHA512Provider.Create());

            case HashFunc.Murmur3:
                return(Murmur3.Create());

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="word"></param>
        /// <returns></returns>
        public int GetRehashLevel(string word)
        {
            if (!this.IsExists(word))
            {
                return(-1);
            }

            int index = HashFunc.CreateHash(word);

            int lvlOfRehash = 1;

            while (values[index].Value != word)
            {
                index = ReHashFunc.Rehash(index, lvlOfRehash);
                lvlOfRehash++;
            }

            return(values[index].LevelOfHash);
        }
Ejemplo n.º 14
0
        public void Registration(string Login, string Password)
        {
            SQLiteConnection db = new SQLiteConnection(DataBasePath);

            UserClass RegUserInfo = new UserClass()
            {
                UserName = HashFunc.GetHash(Login),
                PassWord = HashFunc.GetHash(Password)
            };

            db.Insert(RegUserInfo);

            StorageClass RegStorageInfo = new StorageClass()
            {
                DropBox = null,
                Google  = null,
                Id      = RegUserInfo.Id,
            };

            db.Insert(RegStorageInfo);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Удаляет значение из хэш-таблицы
        /// </summary>
        /// <param name="word">Значение, которое нужно удалить.</param>
        /// <returns>Хэш, по которому хранилось значение.</returns>
        public int Remove(string word)
        {
            if (!this.IsExists(word))
            {
                return(-1);
            }

            int index = HashFunc.CreateHash(word);

            int lvlOfRehash = 1;

            while (values[index].Value != word)
            {
                index = ReHashFunc.Rehash(index, lvlOfRehash);
                lvlOfRehash++;
            }
            values[index] = null;

            this.size--;
            return(index);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Метод проверяет, существует ли такой объект уже в хэш-таблице.
        /// </summary>
        /// <param name="word">Слово, наличие которого в хэш-таблице необходимо проверить.</param>
        /// <returns>Существует ли элемент в хэш-таблице.</returns>
        public bool IsExists(string word)
        {
            if (this.IsEmpty())
            {
                return(false);
            }

            int index = HashFunc.CreateHash(word);

            int startIndex  = index;
            int lvlOfRehash = 1;

            while (values[index] != null & (index != startIndex | lvlOfRehash == 1))
            {
                if (values[index].Value == word)
                {
                    return(true);
                }
                index       = ReHashFunc.Rehash(index, lvlOfRehash);
                lvlOfRehash = (lvlOfRehash + 1) % HashFunc.GetMaxValue();
            }

            return(false);
        }
Ejemplo n.º 17
0
 public CppWrapper(HashFunc func)
 {
     this.Func = func;
 }
Ejemplo n.º 18
0
 public MonoHashTable(IntPtr hash_func, IntPtr compare_func)
 {
     Table   = new Dictionary <IntPtr, object> ();
     Hash    = Marshal.GetDelegateForFunctionPointer <HashFunc> (hash_func);
     Compare = Marshal.GetDelegateForFunctionPointer <EqualityFunc> (compare_func);
 }