• We just launched and are currently in beta. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

How To Change Password Using PHP

yetg

Virtual Environment Auditor
Y Rep
0
0
0
Rep
0
Y Vouches
0
0
0
Vouches
0
Posts
91
Likes
60
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 100 XP
Good Day!!!

In this tutorial, we are going to learn on How To Change Password Using PHP. In any Web Application, changing password is important feature.

result_6.png

Now, let us create a change password using PHP script.
database name - change_password
old password : change_password
Directions:

For CSS Codes

  1. <style type=

    "text/css"

    >
  2. fieldset {
  3. width

    :

    500px

    ;
  4. border

    :

    5px

    dashed

    #CCCCCC

    ;
  5. margin

    :

    0

    auto

    ;
  6. border-radius

    :

    5px

    ;
  7. }

  8. legend {
  9. color

    :

    blue

    ;
  10. font-size

    :

    25px

    ;
  11. }

  12. dl {
  13. float

    :

    right

    ;
  14. width

    :

    390px

    ;
  15. }

  16. dt {
  17. width

    :

    180px

    ;
  18. color

    :

    brown

    ;
  19. font-size

    :

    19px

    ;
  20. }

  21. dd {
  22. width

    :

    200px

    ;
  23. float

    :

    left

    ;
  24. }

  25. dd input {
  26. width

    :

    200px

    ;
  27. border

    :

    2px

    dashed

    #DDD

    ;
  28. font-size

    :

    15px

    ;
  29. text-indent

    :

    5px

    ;
  30. height

    :

    28px

    ;
  31. }

  32. .btn

    {
  33. color

    :

    #fff

    ;
  34. background-color

    :

    dimgrey

    ;
  35. height

    :

    38px

    ;
  36. border

    :

    2px

    solid

    #CCC

    ;
  37. border-radius

    :

    10px

    ;
  38. float

    :

    right

    ;
  39. }

  40. </style>

For HTML Codes

  1. <fieldset

    >
  2. <legend

    >

    Change Password</

    legend

    >
  3. <form

    method

    =

    "post"

    >
  4. <dl

    >
  5. <dt

    >
  6. Old Password
  7. </

    dt

    >
  8. <dd

    >
  9. <input

    type

    =

    "password"

    name

    =

    "old_pass"

    placeholder=

    "Old Password..."

    value

    =

    ""

    required /

    >
  10. </

    dd

    >
  11. </

    dl

    >
  12. <dl

    >
  13. <dt

    >
  14. New Password
  15. </

    dt

    >
  16. <dd

    >
  17. <input

    type

    =

    "password"

    name

    =

    "new_pass"

    placeholder=

    "New Password..."

    value

    =

    ""

    required /

    >
  18. </

    dd

    >
  19. </

    dl

    >
  20. <dl

    >
  21. <dt

    >
  22. Retype New Password
  23. </

    dt

    >
  24. <dd

    >
  25. <input

    type

    =

    "password"

    name

    =

    "re_pass"

    placeholder=

    "Retype New Password..."

    value

    =

    ""

    required /

    >
  26. </

    dd

    >
  27. </

    dl

    >

  28. <p

    align

    =

    "center"

    >
  29. <input

    type

    =

    "submit"

    class

    =

    "btn"

    value

    =

    "Reset Password"

    name

    =

    "re_password"

    /

    >
  30. </

    p

    >
  31. </

    form

    >
  32. </

    fieldset

    >

For PHP Codes

  1. <?php
  2. $conn_db

    =

    mysql_connect

    (

    "localhost"

    ,

    "root"

    ,

    ""

    )

    or die

    (

    )

    ;
  3. $sel_db

    =

    mysql_select_db

    (

    "change_password"

    ,

    $conn_db

    )

    or die

    (

    )

    ;
  4. if

    (

    isset

    (

    $_POST

    [

    're_password'

    ]

    )

    )
  5. {
  6. $old_pass

    =

    $_POST

    [

    'old_pass'

    ]

    ;
  7. $new_pass

    =

    $_POST

    [

    'new_pass'

    ]

    ;
  8. $re_pass

    =

    $_POST

    [

    're_pass'

    ]

    ;
  9. $chg_pwd

    =

    mysql_query

    (

    "select * from users where id='1'"

    )

    ;
  10. $chg_pwd1

    =

    mysql_fetch_array

    (

    $chg_pwd

    )

    ;
  11. $data_pwd

    =

    $chg_pwd1

    [

    'password'

    ]

    ;
  12. if

    (

    $data_pwd

    ==

    $old_pass

    )

    {
  13. if

    (

    $new_pass

    ==

    $re_pass

    )

    {
  14. $update_pwd

    =

    mysql_query

    (

    "update users set password='$new_pass

    ' where id='1'"

    )

    ;
  15. echo

    "<script>alert('Update Sucessfully'); window.location='index.php'</script>"

    ;
  16. }
  17. else

    {
  18. echo

    "<script>alert('Your new and Retype Password is not match'); window.location='index.php'</script>"

    ;
  19. }
  20. }
  21. else
  22. {
  23. echo

    "<script>alert('Your old password is wrong'); window.location='index.php'</script>"

    ;
  24. }

    }
  25. ?>

Full Source Code

  1. <!DOCTYPE html>
  2. <html

    >
  3. <head

    >
  4. <title

    >

    Change Password</

    title

    >
  5. <style

    type

    =

    "text/css"

    >
  6. fieldset {
  7. width:500px;
  8. border:5px dashed #CCCCCC;
  9. margin:0 auto;
  10. border-radius:5px;
  11. }

  12. legend {
  13. color: blue;
  14. font-size: 25px;
  15. }

  16. dl {
  17. float: right;
  18. width: 390px;
  19. }

  20. dt {
  21. width: 180px;
  22. color: brown;
  23. font-size: 19px;
  24. }

  25. dd {
  26. width:200px;
  27. float:left;
  28. }

  29. dd input {
  30. width: 200px;
  31. border: 2px dashed #DDD;
  32. font-size: 15px;
  33. text-indent: 5px;
  34. height: 28px;
  35. }

  36. .btn {
  37. color: #fff;
  38. background-color: dimgrey;
  39. height: 38px;
  40. border: 2px solid #CCC;
  41. border-radius: 10px;
  42. float: right;
  43. }

  44. </

    style

    >
  45. </

    head

    >

  46. <body

    >
  47. <fieldset

    >
  48. <legend

    >

    Change Password</

    legend

    >
  49. <?php
  50. $conn_db =

    mysql_connect(

    "localhost"

    ,"root"

    ,""

    )

    or die(

    )

    ;
  51. $sel_db =

    mysql_select_db(

    "change_password"

    ,$conn_db)

    or die(

    )

    ;
  52. if(

    isset(

    $_POST[

    're_password'

    ]

    )

    )
  53. {
  54. $old_pass=

    $_POST[

    'old_pass'

    ]

    ;
  55. $new_pass=

    $_POST[

    'new_pass'

    ]

    ;
  56. $re_pass=

    $_POST[

    're_pass'

    ]

    ;
  57. $chg_pwd=

    mysql_query(

    "select * from users where id='1'"

    )

    ;
  58. $chg_pwd1=

    mysql_fetch_array(

    $chg_pwd)

    ;
  59. $data_pwd=

    $chg_pwd1[

    'password'

    ]

    ;
  60. if(

    $data_pwd==

    $old_pass)

    {
  61. if(

    $new_pass==

    $re_pass)

    {
  62. $update_pwd=

    mysql_query(

    "update users set password='$new_pass' where id='1'"

    )

    ;
  63. echo "<script>

    alert('Update Sucessfully'); window.location='index.php'</

    script

    >

    ";
  64. }
  65. else{
  66. echo "<script

    >

    alert('Your new and Retype Password is not match'); window.location='index.php'</

    script

    >

    ";
  67. }
  68. }
  69. else
  70. {
  71. echo "<script

    >

    alert('Your old password is wrong'); window.location='index.php'</

    script

    >

    ";
  72. }}
  73. ?>

  74. <form

    method

    =

    "post"

    >
  75. <dl

    >
  76. <dt

    >
  77. Old Password
  78. </

    dt

    >
  79. <dd

    >
  80. <input

    type

    =

    "password"

    name

    =

    "old_pass"

    placeholder=

    "Old Password..."

    value

    =

    ""

    required /

    >
  81. </

    dd

    >
  82. </

    dl

    >
  83. <dl

    >
  84. <dt

    >
  85. New Password
  86. </

    dt

    >
  87. <dd

    >
  88. <input

    type

    =

    "password"

    name

    =

    "new_pass"

    placeholder=

    "New Password..."

    value

    =

    ""

    required /

    >
  89. </

    dd

    >
  90. </

    dl

    >
  91. <dl

    >
  92. <dt

    >
  93. Retype New Password
  94. </

    dt

    >
  95. <dd

    >
  96. <input

    type

    =

    "password"

    name

    =

    "re_pass"

    placeholder=

    "Retype New Password..."

    value

    =

    ""

    required /

    >
  97. </

    dd

    >
  98. </

    dl

    >

  99. <p

    align

    =

    "center"

    >
  100. <input

    type

    =

    "submit"

    class

    =

    "btn"

    value

    =

    "Reset Password"

    name

    =

    "re_password"

    /

    >
  101. </

    p

    >
  102. </

    form

    >
  103. </

    fieldset

    >
  104. </

    body

    >
  105. </

    html

    >

So what can you say about this work? Share your thoughts in the comment section below. Practice Coding. Thank you.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

344,676

344,684

Top