Advertisement
Guest User

Untitled

a guest
May 17th, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.ServiceModel;
  6. using FirebirdSql.Data.FirebirdClient;
  7. using FirebirdSql.Data.Isql;
  8.  
  9. namespace Test.Server
  10. {
  11.     [ServiceContract(Namespace = "Test.Server")]
  12.     public interface IUser
  13.     {
  14.         [OperationContract]
  15.         bool AddUser(string user, string pass);
  16.     }
  17.  
  18.     public class UserService : IUser
  19.     {
  20.         String constring = "server type=Embedded;User=SYSDBA;Pooling=false;Password=masterkey;Database=c:\\Chorus\\data.fdb";
  21.        
  22.     // add new user to the database
  23.         public bool AddUser(string user, string pass)
  24.         {
  25.             using (FbConnection con = new FbConnection(constring))
  26.             {
  27.                 con.Open();
  28.                 if (CheckUser(user, pass, con) == 0)
  29.                 {
  30.                     FbCommand cmd = new FbCommand("INSERT INTO users (name, pass) VALUES ('" + user + "','" + pass + "')", con);
  31.                     cmd.ExecuteNonQuery();
  32.                     return true;
  33.                 }
  34.                 else
  35.                 {
  36.                     return false;
  37.                 }
  38.             }
  39.         }
  40.  
  41.     // check if user exists
  42.         private int CheckUser(string user, string pass, FbConnection con)
  43.         {
  44.         // this is where the exception might be occurring.
  45.         // if i comment out both the lines below and return a dummy value, the problem seems to go away.
  46.         // could this have something to do with integer overflows corrupting the stack?
  47.             FbCommand cmd = new FbCommand("SELECT count(*) FROM users WHERE name='" + user + "' AND pass='" + pass +"'", con);
  48.             return Convert.ToInt32(cmd.ExecuteScalar());
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement