示例#1
0
        private bool ValidateUser(string login, string password)  // вспомогательный метод для валидации пользователя
        {
            bool isValid = false;

            using (AddrBaseContext db = new AddrBaseContext())

            {
                foreach (Person p in db.Persons)
                {
                    string str = Encrypt.CalculateMD5Hash(password).ToString();
                    if ((login == p.login) && (Encrypt.CalculateMD5Hash(password) == p.password))
                    {
                        isValid = true;
                    }
                }

                //try
                //    {
                //    Person person = ( from p in db.Persons
                //                      where p.login == login && Encrypt.CalculateMD5Hash( password ) == p.passwordConfirm
                //                      select p ).FirstOrDefault();
                //    if ( person != null )
                //        {
                //        isValid = true;
                //        }
                //    }
                //catch
                //    {
                //    isValid = false;
                //    }
            }
            return(isValid);
        }
示例#2
0
        public static string GenerateSign(string query, string appid, string pwd, string salt)
        {
            //http://api.fanyi.baidu.com/doc/21
            //appid+q+salt+密钥
            string r = appid + query + salt + pwd;

            return(Encrypt.CalculateMD5Hash(r));
        }
示例#3
0
        public ActionResult Registration(Person person)
        {
            /*  Person pr = new Person();
             *
             * Random rnd = new Random( 1000 );
             * person.person_id = rnd.Next();
             * ViewBag.person_id = person.person_id;
             * //   ps.Add( new Person() {person_id, fio,prv_phone,description} );
             * // db.Persons.Add( person );
             * db.SaveChanges();
             */
            /*  if ( person.login == db.Persons.Find( person.login ).ToString() )
             *    {
             *    person.login = null;
             *    }
             */
            //List<Person> ps = new List<Person>();
            if (person.password == person.passwordConfirm)
            {
                person.password        = Encrypt.CalculateMD5Hash(person.password).ToString();
                person.passwordConfirm = person.password;
            }


            //   ps.Add( new Person() { password } );
            // ViewBag.Persons = person.password;
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                db.SaveChanges();

                /*   try
                 *  {
                 * db.SaveChanges();
                 *  }
                 * catch (DbEntityValidationException excp)
                 *  {
                 *  foreach (DbEntityValidationResult validationError in excp.EntityValidationErrors)
                 *      {
                 *      Response.Write( "Object: " + validationError.Entry.Entity.ToString() );
                 *      Response.Write( " " );
                 *      foreach(DbValidationError err in validationError.ValidationErrors)
                 *          {
                 *          Response.Write( err.ErrorMessage + " " );
                 *          }
                 *      }
                 *  }
                 */

                return(RedirectToAction("Index"));
            }
            return(View(person));
        }
示例#4
0
        public IHttpActionResult PostUSUARIO(USUARIO uSUARIO)
        {
            uSUARIO.INSCRICAO = new HashSet <INSCRICAO>();
            uSUARIO.USUARIO_GERENCIA_EVENTO = new HashSet <USUARIO_GERENCIA_EVENTO>();
            uSUARIO.PERFIL = null;
            uSUARIO.SENHA  = Encrypt.CalculateMD5Hash(uSUARIO.SENHA);
            uSUARIO.ATIVO  = 1;

            db.USUARIO.Add(uSUARIO);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = uSUARIO.COD_USUARIO }, uSUARIO));
        }
示例#5
0
        public IHttpActionResult PutUSUARIO(int id, USUARIO uSUARIO)
        {
            var existingEntity = db.USUARIO.First(x => x.COD_USUARIO == uSUARIO.COD_USUARIO);

            existingEntity.ATIVO      = 1;
            existingEntity.NOME       = uSUARIO.NOME;
            existingEntity.EMAIL      = uSUARIO.EMAIL;
            existingEntity.CELULAR    = uSUARIO.CELULAR;
            existingEntity.COD_PERFIL = uSUARIO.COD_PERFIL;

            if (id != existingEntity.COD_USUARIO)
            {
                return(BadRequest());
            }
            else if (existingEntity.SENHA == uSUARIO.SENHA)
            {
                db.Entry(existingEntity).Property(x => x.SENHA).IsModified = false;
            }
            else
            {
                existingEntity.SENHA           = Encrypt.CalculateMD5Hash(uSUARIO.SENHA);
                db.Entry(existingEntity).State = EntityState.Modified;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!USUARIOExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw new DbUpdateConcurrencyException();
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }