Data Mining

Download Free Data Mining Source Code In C/C++, C#, Visual Basic, Visual Basic.NET, Java,
and other programming languages
Welcome to Data Mining Sign in | Join | Help
in Search

Data Mining Source Code Newsletter

Business Analyst Training
Live, Online, Video Courses
Instructor-Led + Hands-On
BusinessAnalystBootCamp.Com

SQL + Database Training
Live, Online, Video Classes
Instructor-Led + Hands-On
SQLBootCamp.Com

Software Developer Training
Live, Online, Video Courses
Instructor-Led + Hands-On
SoftwareDevelperBootCamp.Com

IT CAREER COACH
Hands-On Experience Coaching
IT Skills Training
IT-Career-Coach.NET

IT Professional Newsletter
"Free" IT Career Success Tips
How To Accelerate Your Career
IT Career Newsletter

Ask IT Career Questions
"ASK" A Burning IT Career
Question Or Get Answers
Ask A Burning IT Question Now!

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed

Create a webservice to authenticate user on the website against the database

Last post 09-12-2003, 13:20 by DotNetSmart. 0 replies.
Sort Posts: Previous Next
  •  09-12-2003, 13:20 682

    Create a webservice to authenticate user on the website against the database

    Hi,

    I have demonstrate a very good example to to create a webservice which will be used to authenticate user on the website against predefined database entry.

    So this is a very basic yet useful example to further enhance webservice capability on the site.

    I have used back-end database as SQL Server 7 and created a database named "Credentials" and created a table named "UserInfo"

    Table Structure
    ===============

    UserID char 10
    Password char 6

    So please create database and table then run the example.


    I have commented the code already to give you an idea of how the things happen. So please go through the code if you still have any problem then please let me know.

    Thanks,

    Best Regards,



    --------------------------------------------------------------------------------



    Imports System.Web.Services
    Imports System.data.OleDb
    _
    Public Class Service1
    Inherits System.Web.Services.WebService

    #Region " Web Services Designer Generated Code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Web Services Designer.
    InitializeComponent()

    'Add your own initialization code after the InitializeComponent() call

    End Sub

    'Required by the Web Services Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Web Services Designer
    'It can be modified using the Web Services Designer.
    'Do not modify it using the code editor.
    Private Sub InitializeComponent()
    components = New System.ComponentModel.Container()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    'CODEGEN: This procedure is required by the Web Services Designer
    'Do not modify it using the code editor.
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub

    #End Region

    ' WEB SERVICE EXAMPLE
    ' The HelloWorld() example service returns the string Hello World.
    ' To build, uncomment the following lines then save and build the project.
    ' To test this web service, ensure that the .asmx file is the start page
    ' and press F5.
    '
    ' _
    'Public Function HelloWorld() As String
    ' Return "Hello World"
    'End Function

    _
    Public Function Login(ByVal UserID As String, ByVal Password As String) As Boolean
    'Retrived password retrieval and initalization
    Dim pass As String = RetrieveData(UserID)
    'Password matching after trimming all the spaces
    If Trim(pass) = Trim(Password) Then
    'if matched then notify back to calling application that user is valid by setting return parameter to true
    Login = True
    Else
    'if not matched then notify back to calling application that user is invalid by setting return parameter to false
    Login = False
    End If
    End Function



    Public Function RetrieveData(ByVal UserID As String) As String
    Try
    Dim connstr As String = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=Credentials;User ID=sa;"
    Dim i As Integer
    Dim myConnection As OleDbConnection
    Dim myCommand As OleDbDataAdapter
    Dim ds As New DataSet
    myConnection = New OleDbConnection(connstr)
    myCommand = New OleDbDataAdapter("Select * from UserInfo where UserID='" & UserID & "'", myConnection)
    myCommand.Fill(ds, "UserInfo")
    Return ds.Tables("UserInfo").Rows(0).Item("Password").ToString
    Catch
    Return ""
    End Try
    End Function


    End Class

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed