Пример #1
0
        public string UpdateToken(int id, string username, string password)
        {
            Token t;
            DateTime expirationDate;
            DateTime createdDate;
            string text;
            MD5 md5;
            byte[] textToHash;
            byte[] result;

            try
            {
                //daca exista un token pentru user preiau obiectul
                t = GetTokenByUserID(id);

                createdDate = DateTime.Now;
                expirationDate = DateTime.Now.AddHours(3);

                //creez token string
                text = t.TokenID.ToString() + username + password + createdDate.ToString();

                md5 = new MD5CryptoServiceProvider();
                textToHash = Encoding.Default.GetBytes(text);
                result = md5.ComputeHash(textToHash);

                //Convert result back to string.
                text = BitConverter.ToString(result);

                try
                {
                    //verificare update
                    _dataAccess.TokenRepository.UpdateToken(t.TokenID, createdDate, expirationDate, text);
                }
                catch (Exception ex)
                {
                    return ex.InnerException.InnerException.Message;
                }
                return text;

            }
            catch
            {
                t = new Token();
                t.UserID = id;

                t.CreatedDate = DateTime.Now;
                t.ExpirationDate = t.CreatedDate.AddHours(3);

                //creez token string
                text = t.TokenID.ToString() + username + t.CreatedDate.ToString();

                md5 = new MD5CryptoServiceProvider();
                textToHash = Encoding.Default.GetBytes(text);
                result = md5.ComputeHash(textToHash);

                //Convert result back to string.
                t.TokenString = BitConverter.ToString(result);

                try
                {
                    //verificare inserare
                    _dataAccess.TokenRepository.Add(t);
                }
                catch (Exception ex)
                {
                    return ex.InnerException.InnerException.Message;
                }

                return t.TokenString;
            }
        }
Пример #2
0
 public void AddToken(Token token)
 {
     _dataAccess.TokenRepository.Add(token);
 }